use of org.bimserver.ifc.BasicIfcModel in project BIMserver by opensourceBIM.
the class SerializerFactory method create.
public Serializer create(Project project, String username, IfcModelInterface model, RenderEnginePlugin renderEnginePlugin, DownloadParameters downloadParameters) throws SerializerException {
DatabaseSession session = bimDatabase.createSession();
try {
SerializerPluginConfiguration serializerPluginConfiguration = session.get(StorePackage.eINSTANCE.getSerializerPluginConfiguration(), downloadParameters.getSerializerOid(), OldQuery.getDefault());
if (serializerPluginConfiguration != null) {
SerializerPlugin serializerPlugin = (SerializerPlugin) pluginManager.getPlugin(serializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
if (serializerPlugin != null) {
ObjectType settings = serializerPluginConfiguration.getSettings();
Serializer serializer = serializerPlugin.createSerializer(new PluginConfiguration(settings));
if (!serializerPlugin.getSupportedSchemas().contains(model.getPackageMetaData().getSchema())) {
SchemaConverterFactory converterFactory = null;
for (Schema schema : serializerPlugin.getSupportedSchemas()) {
converterFactory = bimServer.getSchemaConverterManager().getSchemaConverterFactory(model.getPackageMetaData().getSchema(), schema);
if (converterFactory != null) {
break;
}
}
if (converterFactory == null) {
throw new SerializerException("No usable converter found for schema " + model.getPackageMetaData().getSchema() + " for serializer " + serializerPlugin.getClass().getName());
}
try {
IfcModel targetModel = new BasicIfcModel(bimServer.getMetaDataManager().getPackageMetaData(converterFactory.getTargetSchema().getEPackageName()), new HashMap<Integer, Long>(), (int) model.size());
SchemaConverter converter = converterFactory.create(model, targetModel);
converter.convert();
model = targetModel;
} catch (SchemaConverterException e) {
throw new SerializerException(e);
} catch (IfcModelInterfaceException e) {
throw new SerializerException(e);
}
}
if (serializer != null) {
try {
ProjectInfo projectInfo = new ProjectInfo();
projectInfo.setName(project.getName());
projectInfo.setDescription(project.getDescription());
GeoTag geoTag = project.getGeoTag();
if (geoTag != null && geoTag.getEnabled()) {
projectInfo.setX(geoTag.getX());
projectInfo.setY(geoTag.getY());
projectInfo.setZ(geoTag.getZ());
projectInfo.setDirectionAngle(geoTag.getDirectionAngle());
} else {
projectInfo.setX(4.8900);
projectInfo.setY(52.3700);
}
projectInfo.setAuthorName(username);
serializer.init(model, projectInfo, true);
return serializer;
} catch (NullPointerException e) {
LOGGER.error("", e);
}
}
}
}
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} finally {
session.close();
}
return null;
}
use of org.bimserver.ifc.BasicIfcModel in project BIMserver by opensourceBIM.
the class ServiceRunnerServlet method service.
@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (request.getRequestURI().endsWith("/servicelist")) {
processServiceList(request, response);
return;
}
String token = null;
if (request.getHeader("Authorization") != null) {
String a = request.getHeader("Authorization");
if (a.startsWith("Bearer")) {
token = a.substring(7);
}
}
if (token == null) {
token = request.getHeader("Token");
}
LOGGER.info("Token: " + token);
String serviceName = request.getHeader("ServiceName");
if (serviceName == null) {
serviceName = request.getRequestURI();
if (serviceName.startsWith("/services/")) {
serviceName = serviceName.substring(10);
}
}
LOGGER.info("ServiceName: " + serviceName);
long serviceOid = Long.parseLong(serviceName);
String inputType = request.getHeader("Input-Type");
LOGGER.info("Input-Type: " + inputType);
try (DatabaseSession session = getBimServer().getDatabase().createSession()) {
Authorization authorization = Authorization.fromToken(getBimServer().getEncryptionKey(), token);
User user = session.get(authorization.getUoid(), OldQuery.getDefault());
if (user == null) {
LOGGER.error("Service \"" + serviceName + "\" not found for this user");
throw new UserException("No user found with uoid " + authorization.getUoid());
}
if (user.getState() == ObjectState.DELETED) {
LOGGER.error("User has been deleted");
throw new UserException("User has been deleted");
}
InternalServicePluginConfiguration foundService = null;
UserSettings userSettings = user.getUserSettings();
for (InternalServicePluginConfiguration internalServicePluginConfiguration : userSettings.getServices()) {
if (internalServicePluginConfiguration.getOid() == serviceOid) {
foundService = internalServicePluginConfiguration;
break;
}
}
if (foundService == null) {
LOGGER.info("Service \"" + serviceName + "\" not found for this user");
throw new ServletException("Service \"" + serviceName + "\" not found for this user");
}
PluginDescriptor pluginDescriptor = foundService.getPluginDescriptor();
ServicePlugin servicePlugin = getBimServer().getPluginManager().getServicePlugin(pluginDescriptor.getPluginClassName(), true);
if (servicePlugin instanceof BimBotsServiceInterface) {
LOGGER.info("Found service " + servicePlugin);
BimBotsServiceInterface bimBotsServiceInterface = (BimBotsServiceInterface) servicePlugin;
try {
if (getBimServer().getServerSettingsCache().getServerSettings().isStoreServiceRuns()) {
LOGGER.info("Storing intermediate results");
// When we store service runs, we can just use the streaming deserializer to stream directly to the database, after that we'll trigger the actual service
// Create or find project and link user and service to project
// Checkin stream into project
// Trigger service
ServiceInterface serviceInterface = getBimServer().getServiceFactory().get(authorization, AccessMethod.INTERNAL).get(ServiceInterface.class);
SProject project = serviceInterface.addProject("tmp-" + new Random().nextInt(), "ifc2x3tc1");
SDeserializerPluginConfiguration deserializer = serviceInterface.getSuggestedDeserializerForExtension("ifc", project.getOid());
if (deserializer == null) {
throw new BimBotsException("No deserializer found");
}
serviceInterface.checkin(project.getOid(), "Auto checkin", deserializer.getOid(), -1L, "s", new DataHandler(new InputStreamDataSource(request.getInputStream())), false, true);
project = serviceInterface.getProjectByPoid(project.getOid());
PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(project.getSchema());
IfcModelInterface model = new BasicIfcModel(packageMetaData, null);
try {
Revision revision = session.get(project.getLastRevisionId(), OldQuery.getDefault());
session.getMap(model, new OldQuery(packageMetaData, project.getId(), revision.getId(), revision.getOid(), null, Deep.NO));
} catch (BimserverDatabaseException e) {
e.printStackTrace();
}
BimServerBimBotsInput input = new BimServerBimBotsInput(getBimServer(), authorization.getUoid(), null, null, model);
BimBotsOutput output = bimBotsServiceInterface.runBimBot(input, getBimServer().getSConverter().convertToSObject(foundService.getSettings()));
SExtendedData extendedData = new SExtendedData();
SFile file = new SFile();
file.setData(output.getData());
file.setFilename(output.getContentDisposition());
file.setMime(output.getContentType());
file.setSize(output.getData().length);
Long fileId = serviceInterface.uploadFile(file);
extendedData.setFileId(fileId);
extendedData.setTitle(output.getTitle());
SExtendedDataSchema extendedDataSchema = null;
try {
extendedDataSchema = serviceInterface.getExtendedDataSchemaByName(output.getSchemaName());
} catch (UserException e) {
extendedDataSchema = new SExtendedDataSchema();
extendedDataSchema.setContentType(output.getContentType());
extendedDataSchema.setName(output.getSchemaName());
serviceInterface.addExtendedDataSchema(extendedDataSchema);
}
extendedData.setSchemaId(extendedDataSchema.getOid());
serviceInterface.addExtendedDataToRevision(project.getLastRevisionId(), extendedData);
response.setHeader("Output-Type", output.getSchemaName());
response.setHeader("Data-Title", output.getTitle());
response.setHeader("Data-Identifier", "" + project.getOid());
response.setHeader("Content-Type", output.getContentType());
response.setHeader("Content-Disposition", output.getContentDisposition());
response.getOutputStream().write(output.getData());
} else {
// When we don't store the service runs, there is no other way than to just use the old deserializer and run the service from the EMF model
LOGGER.info("NOT Storing intermediate results");
DeserializerPlugin deserializerPlugin = getBimServer().getPluginManager().getFirstDeserializer("ifc", Schema.IFC2X3TC1, true);
if (deserializerPlugin == null) {
throw new BimBotsException("No deserializer plugin found");
}
byte[] data = IOUtils.toByteArray(request.getInputStream());
SchemaName schema = SchemaName.valueOf(inputType);
Deserializer deserializer = deserializerPlugin.createDeserializer(new PluginConfiguration());
PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData("ifc2x3tc1");
deserializer.init(packageMetaData);
IfcModelInterface model = deserializer.read(new ByteArrayInputStream(data), schema.name(), data.length, null);
BimServerBimBotsInput input = new BimServerBimBotsInput(getBimServer(), authorization.getUoid(), schema, data, model);
BimBotsOutput output = bimBotsServiceInterface.runBimBot(input, getBimServer().getSConverter().convertToSObject(foundService.getSettings()));
response.setHeader("Output-Type", output.getSchemaName());
response.setHeader("Data-Title", output.getTitle());
response.setHeader("Content-Type", output.getContentType());
response.setHeader("Content-Disposition", output.getContentDisposition());
response.getOutputStream().write(output.getData());
}
} catch (BimBotsException e) {
LOGGER.error("", e);
} catch (DeserializeException e) {
LOGGER.error("", e);
} catch (PluginException e) {
LOGGER.error("", e);
} catch (ServerException e) {
LOGGER.error("", e);
}
} else {
throw new ServletException("Service \"" + serviceName + "\" does not implement the BimBotsServiceInterface");
}
} catch (AuthenticationException e) {
LOGGER.error("", e);
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} catch (UserException e) {
LOGGER.error("", e);
}
}
use of org.bimserver.ifc.BasicIfcModel in project BIMserver by opensourceBIM.
the class AdminServiceImpl method regenerateGeometry.
@Override
public void regenerateGeometry(Long croid) throws ServerException, UserException {
LOGGER.info("Regenerating geometry for concrete revision" + croid);
DatabaseSession session = getBimServer().getDatabase().createSession();
try {
// Normally we wouldn't be allowed to change existing data
session.setOverwriteEnabled(true);
ConcreteRevision concreteRevision = session.get(StorePackage.eINSTANCE.getConcreteRevision(), croid, OldQuery.getDefault());
PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
IfcModelInterface model = new BasicIfcModel(packageMetaData, null);
session.getMap(model, new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), -1));
User user = session.get(getAuthorization().getUoid(), OldQuery.getDefault());
UserSettings userSettings = user.getUserSettings();
RenderEnginePluginConfiguration defaultRenderEngine = userSettings.getDefaultRenderEngine();
if (defaultRenderEngine == null) {
throw new BimBotsException("No default render engine has been selected for this user");
}
RenderEnginePool pool = getBimServer().getRenderEnginePools().getRenderEnginePool(model.getPackageMetaData().getSchema(), defaultRenderEngine.getPluginDescriptor().getPluginClassName(), new PluginConfiguration(defaultRenderEngine.getSettings()));
new GeometryGenerator(getBimServer()).generateGeometry(pool, getBimServer().getPluginManager(), session, model, concreteRevision.getProject().getId(), concreteRevision.getId(), true, null);
session.commit();
} catch (Exception e) {
handleException(e);
} finally {
session.close();
}
}
use of org.bimserver.ifc.BasicIfcModel 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();
}
}
}
}
use of org.bimserver.ifc.BasicIfcModel 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();
}
}
Aggregations