use of org.bimserver.emf.IfcModelInterface 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());
}
}
use of org.bimserver.emf.IfcModelInterface 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());
}
}
use of org.bimserver.emf.IfcModelInterface in project BIMserver by opensourceBIM.
the class ServiceImpl method checkinInternal.
private Long checkinInternal(Long topicId, final Long poid, final String comment, Long deserializerOid, Long fileSize, String fileName, InputStream originalInputStream, Boolean merge, Boolean sync, final DatabaseSession session, String username, String userUsername, Project project, Path file, long newServiceId) throws BimserverDatabaseException, UserException, IOException, DeserializeException, CannotBeScheduledException {
if (getBimServer().getCheckinsInProgress().containsKey(poid)) {
throw new UserException("Checkin in progress on this project, please try again later");
}
getBimServer().getCheckinsInProgress().put(poid, getAuthorization().getUoid());
DeserializerPluginConfiguration deserializerPluginConfiguration = session.get(StorePackage.eINSTANCE.getDeserializerPluginConfiguration(), deserializerOid, OldQuery.getDefault());
if (deserializerPluginConfiguration == null) {
throw new UserException("Deserializer with oid " + deserializerOid + " not found");
} else {
PluginBundleVersion pluginBundleVersion = deserializerPluginConfiguration.getPluginDescriptor().getPluginBundleVersion();
Plugin plugin = getBimServer().getPluginManager().getPlugin(deserializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
if (plugin != null) {
if (plugin instanceof DeserializerPlugin) {
DeserializerPlugin deserializerPlugin = (DeserializerPlugin) plugin;
ObjectType settings = deserializerPluginConfiguration.getSettings();
Deserializer deserializer = deserializerPlugin.createDeserializer(new PluginConfiguration(settings));
OutputStream outputStream = Files.newOutputStream(file);
InputStream inputStream = new MultiplexingInputStream(originalInputStream, outputStream);
deserializer.init(getBimServer().getDatabase().getMetaDataManager().getPackageMetaData(project.getSchema()));
IfcModelInterface model = null;
try {
model = deserializer.read(inputStream, fileName, fileSize, null);
} finally {
inputStream.close();
}
CheckinDatabaseAction checkinDatabaseAction = new CheckinDatabaseAction(getBimServer(), null, getInternalAccessMethod(), poid, getAuthorization(), model, comment, fileName, merge, newServiceId);
LongCheckinAction longAction = new LongCheckinAction(topicId, getBimServer(), username, userUsername, getAuthorization(), checkinDatabaseAction);
getBimServer().getLongActionManager().start(longAction);
if (sync) {
longAction.waitForCompletion();
}
return longAction.getProgressTopic().getKey().getId();
} else if (plugin instanceof StreamingDeserializerPlugin) {
StreamingDeserializerPlugin streaminDeserializerPlugin = (StreamingDeserializerPlugin) plugin;
ObjectType settings = deserializerPluginConfiguration.getSettings();
StreamingDeserializer streamingDeserializer = streaminDeserializerPlugin.createDeserializer(new PluginConfiguration(settings));
streamingDeserializer.init(getBimServer().getDatabase().getMetaDataManager().getPackageMetaData(project.getSchema()));
RestartableInputStream restartableInputStream = new RestartableInputStream(originalInputStream, file);
StreamingCheckinDatabaseAction checkinDatabaseAction = new StreamingCheckinDatabaseAction(getBimServer(), null, getInternalAccessMethod(), poid, getAuthorization(), comment, fileName, restartableInputStream, streamingDeserializer, fileSize, newServiceId, pluginBundleVersion);
LongStreamingCheckinAction longAction = new LongStreamingCheckinAction(topicId, getBimServer(), username, userUsername, getAuthorization(), checkinDatabaseAction);
getBimServer().getLongActionManager().start(longAction);
if (sync) {
longAction.waitForCompletion();
}
return longAction.getProgressTopic().getKey().getId();
} else {
throw new UserException("No (enabled) (streaming) deserializer found with oid " + deserializerOid);
}
} else {
throw new UserException("No (enabled) (streaming) deserializer found with oid " + deserializerOid);
}
}
}
use of org.bimserver.emf.IfcModelInterface in project BIMserver by opensourceBIM.
the class BranchToExistingProjectDatabaseAction method execute.
@Override
public ConcreteRevision execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
Revision oldRevision = getDatabaseSession().get(StorePackage.eINSTANCE.getRevision(), roid, OldQuery.getDefault());
Project oldProject = oldRevision.getProject();
User user = getDatabaseSession().get(StorePackage.eINSTANCE.getUser(), authorization.getUoid(), OldQuery.getDefault());
if (!authorization.hasRightsOnProjectOrSuperProjectsOrSubProjects(user, oldProject)) {
throw new UserException("User has insufficient rights to download revisions from this project");
}
IfcModelSet ifcModelSet = new IfcModelSet();
PackageMetaData lastMetaData = null;
for (ConcreteRevision subRevision : oldRevision.getConcreteRevisions()) {
PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(subRevision.getProject().getSchema());
IfcModel subModel = new BasicIfcModel(packageMetaData, null);
getDatabaseSession().getMap(subModel, new OldQuery(packageMetaData, subRevision.getProject().getId(), subRevision.getId(), -1, Deep.YES));
subModel.getModelMetaData().setDate(subRevision.getDate());
ifcModelSet.add(subModel);
lastMetaData = packageMetaData;
}
IfcModelInterface model = new BasicIfcModel(lastMetaData, null);
try {
model = bimServer.getMergerFactory().createMerger(getDatabaseSession(), authorization.getUoid()).merge(oldRevision.getProject(), ifcModelSet, new ModelHelper(bimServer.getMetaDataManager(), model));
} catch (MergeException e) {
throw new UserException(e);
}
model.resetOids();
CheckinDatabaseAction checkinDatabaseAction = new CheckinDatabaseAction(bimServer, getDatabaseSession(), getAccessMethod(), destPoid, authorization, model, comment, comment, false, -1);
return checkinDatabaseAction.execute();
}
use of org.bimserver.emf.IfcModelInterface in project BIMserver by opensourceBIM.
the class CheckinDatabaseAction method execute.
@Override
public ConcreteRevision execute() throws UserException, BimserverDatabaseException {
try {
bimServer.getCheckinsInProgress().put(poid, getActingUid());
if (fileSize == -1) {
setProgress("Deserializing IFC file...", -1);
} else {
setProgress("Deserializing IFC file...", 0);
}
if (getModel().size() == 0) {
throw new DeserializeException("Cannot checkin empty model");
}
authorization.canCheckin(poid);
project = getProjectByPoid(poid);
int nrConcreteRevisionsBefore = project.getConcreteRevisions().size();
User user = getUserByUoid(authorization.getUoid());
if (project == null) {
throw new UserException("Project with poid " + poid + " not found");
}
if (!authorization.hasRightsOnProjectOrSuperProjects(user, project)) {
throw new UserException("User has no rights to checkin models to this project");
}
if (!MailSystem.isValidEmailAddress(user.getUsername())) {
throw new UserException("Users must have a valid e-mail address to checkin");
}
if (getModel() != null) {
checkCheckSum(project, getModel());
}
long size = 0;
if (getModel() != null) {
for (IdEObject idEObject : getModel().getValues()) {
if (idEObject.eClass().getEAnnotation("hidden") == null) {
size++;
}
}
getModel().fixInverseMismatches();
}
for (ModelCheckerInstance modelCheckerInstance : project.getModelCheckers()) {
if (modelCheckerInstance.isValid()) {
ModelCheckerPlugin modelCheckerPlugin = bimServer.getPluginManager().getModelCheckerPlugin(modelCheckerInstance.getModelCheckerPluginClassName(), true);
if (modelCheckerPlugin != null) {
ModelChecker modelChecker = modelCheckerPlugin.createModelChecker(null);
ModelCheckerResult result = modelChecker.check(getModel(), modelCheckerInstance.getCompiled());
if (!result.isValid()) {
throw new UserException("Model is not valid according to " + modelCheckerInstance.getName());
}
}
}
}
CreateRevisionResult result = createNewConcreteRevision(getDatabaseSession(), size, project, user, comment.trim());
concreteRevision = result.getConcreteRevision();
IfcHeader ifcHeader = getModel().getModelMetaData().getIfcHeader();
if (ifcHeader != null) {
getDatabaseSession().store(ifcHeader);
concreteRevision.setIfcHeader(ifcHeader);
}
project.getConcreteRevisions().add(concreteRevision);
if (getModel() != null) {
concreteRevision.setChecksum(getModel().getModelMetaData().getChecksum());
}
final NewRevisionAdded newRevisionAdded = getDatabaseSession().create(NewRevisionAdded.class);
newRevisionAdded.setDate(new Date());
newRevisionAdded.setExecutor(user);
final Revision revision = concreteRevision.getRevisions().get(0);
if (newServiceId != -1) {
NewService newService = getDatabaseSession().get(newServiceId, OldQuery.getDefault());
revision.getServicesLinked().add(newService);
}
concreteRevision.setSummary(new SummaryMap(getModel()).toRevisionSummary(getDatabaseSession()));
// If this revision is being created by an external service, store a link to the service in the revision
if (authorization instanceof ExplicitRightsAuthorization) {
ExplicitRightsAuthorization explicitRightsAuthorization = (ExplicitRightsAuthorization) authorization;
if (explicitRightsAuthorization.getSoid() != -1) {
Service service = getDatabaseSession().get(explicitRightsAuthorization.getSoid(), OldQuery.getDefault());
revision.setService(service);
}
}
newRevisionAdded.setRevision(revision);
newRevisionAdded.setProject(project);
newRevisionAdded.setAccessMethod(getAccessMethod());
Revision lastRevision = project.getLastRevision();
IfcModelInterface ifcModel = null;
if (merge && lastRevision != null) {
ifcModel = checkinMerge(lastRevision);
} else {
ifcModel = getModel();
}
ifcModel.fixOidsFlat(getDatabaseSession());
if (bimServer.getServerSettingsCache().getServerSettings().isGenerateGeometryOnCheckin()) {
setProgress("Generating Geometry...", -1);
UserSettings userSettings = user.getUserSettings();
RenderEnginePluginConfiguration defaultRenderEngine = userSettings.getDefaultRenderEngine();
if (defaultRenderEngine == null) {
throw new UserException("No default render engine has been selected for this user");
}
RenderEnginePool pool = bimServer.getRenderEnginePools().getRenderEnginePool(model.getPackageMetaData().getSchema(), defaultRenderEngine.getPluginDescriptor().getPluginClassName(), new PluginConfiguration(defaultRenderEngine.getSettings()));
GenerateGeometryResult generateGeometry = new GeometryGenerator(bimServer).generateGeometry(pool, bimServer.getPluginManager(), getDatabaseSession(), ifcModel, project.getId(), concreteRevision.getId(), true, geometryCache);
concreteRevision.setMinBounds(generateGeometry.getMinBoundsAsVector3f());
concreteRevision.setMaxBounds(generateGeometry.getMaxBoundsAsVector3f());
for (Revision other : concreteRevision.getRevisions()) {
other.setHasGeometry(true);
}
}
if (nrConcreteRevisionsBefore != 0 && !merge) {
// There already was a revision, lets delete it (only when not merging)
concreteRevision.setClear(true);
}
Set<EClass> eClasses = ifcModel.getUsedClasses();
Map<EClass, Long> startOids = getDatabaseSession().getStartOids();
if (startOids == null) {
throw new BimserverDatabaseException("No objects changed");
}
int s = 0;
for (EClass eClass : eClasses) {
if (!DatabaseSession.perRecordVersioning(eClass)) {
s++;
}
}
ByteBuffer buffer = ByteBuffer.allocate(8 * s);
buffer.order(ByteOrder.LITTLE_ENDIAN);
for (EClass eClass : eClasses) {
long oid = startOids.get(eClass);
if (!DatabaseSession.perRecordVersioning(eClass)) {
buffer.putLong(oid);
}
}
concreteRevision.setOidCounters(buffer.array());
if (ifcModel != null) {
getDatabaseSession().store(ifcModel.getValues(), project.getId(), concreteRevision.getId());
}
getDatabaseSession().addPostCommitAction(new PostCommitAction() {
@Override
public void execute() throws UserException {
bimServer.getCheckinsInProgress().remove(poid);
bimServer.getNotificationsManager().notify(new NewRevisionNotification(bimServer, project.getOid(), revision.getOid(), authorization));
}
});
getDatabaseSession().store(concreteRevision);
getDatabaseSession().store(project);
} catch (Throwable e) {
if (e instanceof BimserverDatabaseException) {
throw (BimserverDatabaseException) e;
}
if (e instanceof UserException) {
throw (UserException) e;
}
LOGGER.error("", e);
throw new UserException(e);
}
return concreteRevision;
}
Aggregations