Search in sources :

Example 11 with SSerializerPluginConfiguration

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

the class BimServerClient method getGeometry.

@Override
public Geometry getGeometry(long roid, IdEObject ifcProduct) {
    try {
        SSerializerPluginConfiguration serializerByPluginClassName = getPluginInterface().getSerializerByPluginClassName("org.bimserver.serializers.binarygeometry.BinaryGeometrySerializerPlugin");
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        download(roid, serializerByPluginClassName.getOid(), outputStream);
        Files.write(Paths.get("bin.bin"), outputStream.toByteArray());
        ByteArrayInputStream bain = new ByteArrayInputStream(outputStream.toByteArray());
        return new Geometry(bain, ifcProduct.getOid());
    } catch (ServerException e) {
        e.printStackTrace();
    } catch (UserException e) {
        e.printStackTrace();
    } catch (PublicInterfaceNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (BimServerClientException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : Geometry(org.bimserver.plugins.services.Geometry) ServerException(org.bimserver.shared.exceptions.ServerException) ByteArrayInputStream(java.io.ByteArrayInputStream) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UserException(org.bimserver.shared.exceptions.UserException) IOException(java.io.IOException) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException)

Example 12 with SSerializerPluginConfiguration

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

the class NewServicesImpl method listAvailableOutputFormats.

@Override
public List<SFormatSerializerMap> listAvailableOutputFormats(Long poid) throws ServerException, UserException {
    Map<String, SFormatSerializerMap> outputs = new HashMap<>();
    try (DatabaseSession session = getBimServer().getDatabase().createSession()) {
        Project project = session.get(poid, OldQuery.getDefault());
        try {
            List<SSerializerPluginConfiguration> allSerializersForPoids = getServiceMap().get(PluginInterface.class).getAllSerializersForPoids(true, Collections.singleton(poid));
            for (SSerializerPluginConfiguration pluginConfiguration : allSerializersForPoids) {
                PluginDescriptor pluginDescriptor = session.get(pluginConfiguration.getPluginDescriptorId(), OldQuery.getDefault());
                Plugin plugin = getBimServer().getPluginManager().getPlugin(pluginDescriptor.getIdentifier(), true);
                String outputFormat = null;
                // TODO For now only streaming serializers
                if (plugin instanceof StreamingSerializerPlugin) {
                    outputFormat = ((StreamingSerializerPlugin) plugin).getOutputFormat(Schema.valueOf(project.getSchema().toUpperCase()));
                }
                if (outputFormat != null) {
                    SFormatSerializerMap map = outputs.get(outputFormat);
                    if (map == null) {
                        map = new SFormatSerializerMap();
                        map.setFormat(outputFormat);
                        outputs.put(outputFormat, map);
                    }
                    map.getSerializers().add(pluginConfiguration);
                }
            }
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (UserException e) {
            e.printStackTrace();
        }
        return new ArrayList<>(outputs.values());
    } catch (BimserverDatabaseException e) {
        return handleException(e);
    }
}
Also used : ServerException(org.bimserver.shared.exceptions.ServerException) HashMap(java.util.HashMap) DatabaseSession(org.bimserver.database.DatabaseSession) PluginInterface(org.bimserver.shared.interfaces.PluginInterface) ArrayList(java.util.ArrayList) SFormatSerializerMap(org.bimserver.interfaces.objects.SFormatSerializerMap) StreamingSerializerPlugin(org.bimserver.plugins.serializers.StreamingSerializerPlugin) Project(org.bimserver.models.store.Project) PluginDescriptor(org.bimserver.models.store.PluginDescriptor) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException) StreamingSerializerPlugin(org.bimserver.plugins.serializers.StreamingSerializerPlugin) Plugin(org.bimserver.plugins.Plugin)

Example 13 with SSerializerPluginConfiguration

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

the class PluginServiceImpl method addSerializer.

@Override
public Long addSerializer(SSerializerPluginConfiguration serializer) throws ServerException, UserException {
    requireRealUserAuthentication();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        SerializerPluginConfiguration convert = getBimServer().getSConverter().convertFromSObject(serializer, session);
        return session.executeAndCommitAction(new AddSerializerDatabaseAction(session, getInternalAccessMethod(), getAuthorization(), convert));
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : AddSerializerDatabaseAction(org.bimserver.database.actions.AddSerializerDatabaseAction) DatabaseSession(org.bimserver.database.DatabaseSession) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) IOException(java.io.IOException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) UserException(org.bimserver.shared.exceptions.UserException)

Example 14 with SSerializerPluginConfiguration

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

the class PluginServiceImpl method getAllSerializers.

@Override
public List<SSerializerPluginConfiguration> getAllSerializers(Boolean onlyEnabled) throws ServerException, UserException {
    requireRealUserAuthentication();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        UserSettings userSettings = getUserSettings(session);
        List<SSerializerPluginConfiguration> sSerializers = new ArrayList<SSerializerPluginConfiguration>();
        for (SerializerPluginConfiguration serializerPluginConfiguration : userSettings.getSerializers()) {
            if (!onlyEnabled || (serializerPluginConfiguration.getEnabled() && serializerPluginConfiguration.getPluginDescriptor().getEnabled())) {
                sSerializers.add(getBimServer().getSConverter().convertToSObject(serializerPluginConfiguration));
            }
        }
        Collections.sort(sSerializers, new SPluginConfigurationComparator());
        return sSerializers;
    } catch (Exception e) {
        handleException(e);
    } finally {
        session.close();
    }
    return null;
}
Also used : SPluginConfigurationComparator(org.bimserver.webservices.SPluginConfigurationComparator) DatabaseSession(org.bimserver.database.DatabaseSession) UserSettings(org.bimserver.models.store.UserSettings) ArrayList(java.util.ArrayList) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) IOException(java.io.IOException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) UserException(org.bimserver.shared.exceptions.UserException)

Example 15 with SSerializerPluginConfiguration

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

the class PluginServiceImpl method updateSerializer.

@Override
public void updateSerializer(SSerializerPluginConfiguration serializer) throws ServerException, UserException {
    requireRealUserAuthentication();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        SerializerPluginConfiguration convert = session.get(serializer.getOid(), OldQuery.getDefault());
        getBimServer().getSConverter().convertFromSObject(serializer, convert, session);
        session.executeAndCommitAction(new UpdateSerializerDatabaseAction(session, getInternalAccessMethod(), convert));
    } catch (Exception e) {
        handleException(e);
    } finally {
        session.close();
    }
}
Also used : UpdateSerializerDatabaseAction(org.bimserver.database.actions.UpdateSerializerDatabaseAction) DatabaseSession(org.bimserver.database.DatabaseSession) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) IOException(java.io.IOException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) UserException(org.bimserver.shared.exceptions.UserException)

Aggregations

SSerializerPluginConfiguration (org.bimserver.interfaces.objects.SSerializerPluginConfiguration)31 SProject (org.bimserver.interfaces.objects.SProject)24 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)23 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)17 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)15 Test (org.junit.Test)15 IOException (java.io.IOException)11 URL (java.net.URL)11 PublicInterfaceNotFoundException (org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)10 ServerException (org.bimserver.shared.exceptions.ServerException)10 UserException (org.bimserver.shared.exceptions.UserException)10 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)7 IfcModelInterface (org.bimserver.emf.IfcModelInterface)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 DatabaseSession (org.bimserver.database.DatabaseSession)5 ServiceException (org.bimserver.shared.exceptions.ServiceException)5 FileOutputStream (java.io.FileOutputStream)4 InputStream (java.io.InputStream)4 Path (java.nio.file.Path)4 SModelComparePluginConfiguration (org.bimserver.interfaces.objects.SModelComparePluginConfiguration)4