use of org.bimserver.shared.HashMapVirtualObject in project BIMserver by opensourceBIM.
the class QueryPropertiesAndTypesStackFrame method processPropertySet.
@SuppressWarnings("unchecked")
private void processPropertySet(DatabaseSession databaseSession, Set<String> propertyKeysMatched, Long ifcPropertySetDefinition) throws BimserverDatabaseException {
EClass eClassForOid = databaseSession.getEClassForOid(ifcPropertySetDefinition);
if (getPackageMetaData().getEClass("IfcPropertySet").isSuperTypeOf(eClassForOid)) {
HashMapVirtualObject ifcPropertySet = getByOid(ifcPropertySetDefinition);
String propertySetName = (String) ifcPropertySet.get("Name");
Properties propertiesObject = (Properties) properties.get(propertySetName);
if (propertiesObject != null) {
List<Long> properties = (List<Long>) ifcPropertySet.get("HasProperties");
for (long propertyOid : properties) {
if (getPackageMetaData().getEClass("IfcPropertySingleValue").isSuperTypeOf(databaseSession.getEClassForOid(propertyOid))) {
HashMapVirtualObject property = getByOid(propertyOid);
String name = (String) property.get("Name");
HashMapWrappedVirtualObject value = (HashMapWrappedVirtualObject) property.get("NominalValue");
if (propertiesObject.has(name)) {
Object queryPropertyValue = propertiesObject.get(name);
Object wrappedValue = value.eGet(value.eClass().getEStructuralFeature("wrappedValue"));
if (value.eClass().getName().equals("IfcBoolean")) {
Enumerator tristate = (Enumerator) wrappedValue;
if (tristate.getName().toLowerCase().equals(queryPropertyValue.toString())) {
propertyKeysMatched.add(propertySetName + "___" + name);
}
} else if (wrappedValue.equals(queryPropertyValue)) {
propertyKeysMatched.add(propertySetName + "___" + name);
}
}
}
}
}
} else if (getPackageMetaData().getEClass("IfcPropertySetDefinition").isSuperTypeOf(eClassForOid)) {
HashMapVirtualObject ifcPropertySet = getByOid(ifcPropertySetDefinition);
Properties propertiesObject = (Properties) properties.get(ifcPropertySet.eClass().getName());
if (propertiesObject != null) {
for (String key : propertiesObject.keys()) {
if (ifcPropertySet.has(key)) {
if (ifcPropertySet.get(key).toString().equals(propertiesObject.get(key))) {
propertyKeysMatched.add(ifcPropertySet.eClass().getName() + "___" + key);
}
}
}
}
} else {
LOGGER.info(eClassForOid.getName());
}
}
use of org.bimserver.shared.HashMapVirtualObject in project BIMserver by opensourceBIM.
the class QueryPropertiesAndTypesStackFrame method process.
@SuppressWarnings("unchecked")
@Override
public boolean process() throws BimserverDatabaseException, QueryException {
if (typeRecordIterator == null) {
return true;
}
if (record == null) {
currentObject = null;
typeRecordIterator.close();
return true;
}
currentObject = null;
ByteBuffer nextKeyStart = ByteBuffer.allocate(12);
getQueryObjectProvider().incReads();
ByteBuffer keyBuffer = ByteBuffer.wrap(record.getKey());
int keyPid = keyBuffer.getInt();
long keyOid = keyBuffer.getLong();
int keyRid = -keyBuffer.getInt();
ByteBuffer valueBuffer = ByteBuffer.wrap(record.getValue());
GetResult map = getMap(eClass, eClass, valueBuffer, keyPid, keyOid, keyRid);
if (map == GetResult.CONTINUE_WITH_NEXT_OID) {
nextKeyStart.position(0);
nextKeyStart.putInt(getReusable().getPid());
nextKeyStart.putLong(keyOid + 1);
record = typeRecordIterator.next(nextKeyStart.array());
} else {
record = typeRecordIterator.next();
}
if (currentObject != null) {
DatabaseSession databaseSession = getQueryObjectProvider().getDatabaseSession();
List<Long> isDefinedByOids = (List<Long>) currentObject.get("IsDefinedBy");
int totalQueryProperties = 0;
for (String key : this.properties.keySet()) {
totalQueryProperties += this.properties.get(key).count();
}
if (isDefinedByOids != null) {
Set<String> propertyKeysMatched = new HashSet<>();
for (Long definedByOid : isDefinedByOids) {
EClass eClass = databaseSession.getEClassForOid(definedByOid);
if (getPackageMetaData().getEClass("IfcRelDefinesByProperties").isSuperTypeOf(eClass)) {
HashMapVirtualObject ifcRelDefinesByProperties = getByOid(definedByOid);
Long ifcPropertySetDefinition = (Long) ifcRelDefinesByProperties.get("RelatingPropertyDefinition");
processPropertySet(databaseSession, propertyKeysMatched, ifcPropertySetDefinition);
} else if (getPackageMetaData().getEClass("IfcRelDefinesByType").isSuperTypeOf(eClass)) {
HashMapVirtualObject ifcRelDefinesByType = getByOid(definedByOid);
Long relatingTypeId = (Long) ifcRelDefinesByType.get("RelatingType");
EClass eClassForOid = databaseSession.getEClassForOid(relatingTypeId);
if (getPackageMetaData().getEClass("IfcTypeObject").isSuperTypeOf(eClassForOid)) {
HashMapVirtualObject ifcTypeObject = getByOid(relatingTypeId);
List<Long> propertySets = (List<Long>) ifcTypeObject.get("HasPropertySets");
if (propertySets != null) {
for (Long propertySetId : propertySets) {
processPropertySet(databaseSession, propertyKeysMatched, propertySetId);
}
}
}
} else {
LOGGER.info(eClass.getName());
}
}
if (propertyKeysMatched.size() != totalQueryProperties) {
// All properties should have matched, atm all properties provided in the query are evaluated as AND
currentObject = null;
}
}
}
processPossibleIncludes(currentObject, eClass, getQueryPart());
return false;
}
use of org.bimserver.shared.HashMapVirtualObject in project BIMserver by opensourceBIM.
the class DatabaseReadingStackFrame method getByOid.
public HashMapVirtualObject getByOid(long oid, boolean useCache) throws BimserverDatabaseException {
HashMapVirtualObject byOid = getQueryObjectProvider().getFromCache((long) oid);
if (byOid != null) {
return byOid;
}
EClass eClass = getQueryObjectProvider().getDatabaseSession().getEClassForOid(oid);
ByteBuffer mustStartWith = ByteBuffer.wrap(new byte[12]);
mustStartWith.putInt(reusable.getPid());
mustStartWith.putLong(oid);
ByteBuffer startSearchWith = ByteBuffer.wrap(new byte[16]);
startSearchWith.putInt(reusable.getPid());
startSearchWith.putLong(oid);
startSearchWith.putInt(-reusable.getRid());
SearchingRecordIterator recordIterator = getQueryObjectProvider().getDatabaseSession().getKeyValueStore().getRecordIterator(eClass.getEPackage().getName() + "_" + eClass.getName(), mustStartWith.array(), startSearchWith.array(), getQueryObjectProvider().getDatabaseSession());
try {
Record record = recordIterator.next();
if (record == null) {
return null;
}
getQueryObjectProvider().incReads();
ByteBuffer keyBuffer = ByteBuffer.wrap(record.getKey());
ByteBuffer valueBuffer = ByteBuffer.wrap(record.getValue());
// pid
keyBuffer.getInt();
long keyOid = keyBuffer.getLong();
int keyRid = -keyBuffer.getInt();
if (keyRid <= reusable.getRid()) {
if (valueBuffer.capacity() == 1 && valueBuffer.get(0) == -1) {
valueBuffer.position(valueBuffer.position() + 1);
return null;
// deleted entity
} else {
byOid = convertByteArrayToObject(eClass, keyOid, valueBuffer, keyRid);
if (byOid != null && useCache) {
getQueryObjectProvider().cache(byOid);
}
return byOid;
}
} else {
return null;
}
} finally {
recordIterator.close();
}
}
use of org.bimserver.shared.HashMapVirtualObject in project BIMserver by opensourceBIM.
the class QueryBoundingBoxStackFrame method process.
@Override
public boolean process() throws BimserverDatabaseException, QueryException {
if (typeRecordIterator == null) {
return true;
}
if (record == null) {
currentObject = null;
typeRecordIterator.close();
return true;
}
currentObject = null;
ByteBuffer nextKeyStart = ByteBuffer.allocate(12);
getQueryObjectProvider().incReads();
ByteBuffer keyBuffer = ByteBuffer.wrap(record.getKey());
int keyPid = keyBuffer.getInt();
long keyOid = keyBuffer.getLong();
int keyRid = -keyBuffer.getInt();
ByteBuffer valueBuffer = ByteBuffer.wrap(record.getValue());
GetResult map = getMap(eClass, eClass, valueBuffer, keyPid, keyOid, keyRid);
if (map == GetResult.CONTINUE_WITH_NEXT_OID) {
nextKeyStart.position(0);
nextKeyStart.putInt(getReusable().getPid());
nextKeyStart.putLong(keyOid + 1);
record = typeRecordIterator.next(nextKeyStart.array());
} else {
record = typeRecordIterator.next();
}
if (currentObject != null) {
if (currentObject.has("geometry")) {
long geometryInfoId = (Long) currentObject.get("geometry");
HashMapVirtualObject geometryInfo = getByOid(geometryInfoId);
// TODO the querying party should be able to force the units used
// TODO use some spatial indexing, this is getting slow now that it's actually used
boolean hasAny = !Double.isNaN(inBoundingBox.getX()) || !Double.isNaN(inBoundingBox.getY()) || !Double.isNaN(inBoundingBox.getZ()) || !Double.isNaN(inBoundingBox.getWidth()) || !Double.isNaN(inBoundingBox.getHeight()) || !Double.isNaN(inBoundingBox.getDepth());
if (inBoundingBox.getDensityLowerThreshold() != null) {
float density = (float) geometryInfo.get("density");
if (density > inBoundingBox.getDensityLowerThreshold()) {
currentObject = null;
return false;
}
}
if (inBoundingBox.getDensityUpperThreshold() != null) {
float density = (float) geometryInfo.get("density");
if (density <= inBoundingBox.getDensityUpperThreshold()) {
currentObject = null;
return false;
}
}
if (hasAny) {
HashMapWrappedVirtualObject bounds = (HashMapWrappedVirtualObject) geometryInfo.get("boundsMm");
HashMapWrappedVirtualObject minBounds = (HashMapWrappedVirtualObject) bounds.eGet("min");
HashMapWrappedVirtualObject maxBounds = (HashMapWrappedVirtualObject) bounds.eGet("max");
double minX = (double) minBounds.eGet("x");
double minY = (double) minBounds.eGet("y");
double minZ = (double) minBounds.eGet("z");
double maxX = (double) maxBounds.eGet("x");
double maxY = (double) maxBounds.eGet("y");
double maxZ = (double) maxBounds.eGet("z");
if (inBoundingBox.isPartial()) {
// }
if (minX >= inBoundingBox.getX() && minY >= inBoundingBox.getY() && minZ >= inBoundingBox.getZ() && maxX <= inBoundingBox.getX() + inBoundingBox.getWidth() && maxY <= inBoundingBox.getY() + inBoundingBox.getHeight() && maxZ <= inBoundingBox.getZ() + inBoundingBox.getDepth()) {
// OK
} else if (minX <= inBoundingBox.getX() && minY <= inBoundingBox.getY() && minZ <= inBoundingBox.getZ() && maxX >= inBoundingBox.getX() + inBoundingBox.getWidth() && maxY >= inBoundingBox.getY() + inBoundingBox.getHeight() && maxZ >= inBoundingBox.getZ() + inBoundingBox.getDepth()) {
// OK
} else {
if ((minX <= inBoundingBox.getX() + inBoundingBox.getWidth() && maxX >= inBoundingBox.getX()) && (minY <= inBoundingBox.getY() + inBoundingBox.getHeight() && maxY >= inBoundingBox.getY()) && (minZ <= inBoundingBox.getZ() + inBoundingBox.getDepth() && maxZ >= inBoundingBox.getZ())) {
// OK
} else {
currentObject = null;
}
}
} else if (inBoundingBox.isUseCenterPoint()) {
double centerX = (minX + maxX) / 2f;
double centerY = (minY + maxY) / 2f;
double centerZ = (minZ + maxZ) / 2f;
if (centerX > inBoundingBox.getX() && centerY > inBoundingBox.getY() && centerZ > inBoundingBox.getZ() && centerX <= inBoundingBox.getX() + inBoundingBox.getWidth() && centerY <= inBoundingBox.getY() + inBoundingBox.getHeight() && centerZ <= inBoundingBox.getZ() + inBoundingBox.getDepth()) {
} else {
currentObject = null;
}
} else {
if (minX > inBoundingBox.getX() && minY > inBoundingBox.getY() && minZ > inBoundingBox.getZ() && maxX <= inBoundingBox.getX() + inBoundingBox.getWidth() && maxY <= inBoundingBox.getY() + inBoundingBox.getHeight() && maxZ <= inBoundingBox.getZ() + inBoundingBox.getDepth()) {
if (inBoundingBox.isExcludeOctants()) {
for (int x = 0; x < 2; x++) {
for (int y = 0; y < 2; y++) {
for (int z = 0; z < 2; z++) {
if (minX > inBoundingBox.getX() + (x * inBoundingBox.getWidth() / 2) && minY > inBoundingBox.getY() + (y * inBoundingBox.getHeight() / 2) && minZ > inBoundingBox.getZ() + (z * inBoundingBox.getDepth() / 2) && maxX < inBoundingBox.getX() + ((x == 0 ? 0.5f : 1f) * inBoundingBox.getWidth()) && maxY < inBoundingBox.getY() + ((y == 0 ? 0.5f : 1f) * inBoundingBox.getHeight()) && maxZ < inBoundingBox.getZ() + ((z == 0 ? 0.5f : 1f) * inBoundingBox.getDepth())) {
currentObject = null;
break;
}
}
}
}
} else {
// OK
}
} else {
currentObject = null;
}
}
}
} else {
currentObject = null;
}
}
processPossibleIncludes(currentObject, eClass, getQueryPart());
return false;
}
use of org.bimserver.shared.HashMapVirtualObject in project BIMserver by opensourceBIM.
the class CommitTransactionDatabaseAction method execute.
@Override
public ConcreteRevision execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
Project project = getProjectByPoid(longTransaction.getPoid());
User user = getUserByUoid(authorization.getUoid());
if (project == null) {
throw new UserException("Project with poid " + longTransaction.getPoid() + " 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");
}
long size = 0;
Revision previousRevision = project.getLastRevision();
ConcreteRevision previousConcreteRevision = null;
if (previousRevision != null) {
previousConcreteRevision = previousRevision.getConcreteRevisions().get(0);
}
if (project.getLastRevision() != null) {
size += project.getLastRevision().getSize();
}
for (Change change : longTransaction.getChanges()) {
if (change instanceof CreateObjectChange) {
size++;
} else if (change instanceof RemoveObjectChange) {
size--;
}
}
Revision oldLastRevision = project.getLastRevision();
CreateRevisionResult result = createNewConcreteRevision(getDatabaseSession(), size, project, user, comment.trim());
ConcreteRevision concreteRevision = result.getConcreteRevision();
if (previousConcreteRevision != null) {
concreteRevision.setIfcHeader(previousConcreteRevision.getIfcHeader());
}
revision = concreteRevision.getRevisions().get(0);
project.setLastRevision(revision);
final NewRevisionAdded newRevisionAdded = getDatabaseSession().create(NewRevisionAdded.class);
newRevisionAdded.setDate(new Date());
newRevisionAdded.setExecutor(user);
newRevisionAdded.setRevision(concreteRevision.getRevisions().get(0));
newRevisionAdded.setProject(project);
newRevisionAdded.setAccessMethod(getAccessMethod());
OidCounters originalOidCounters = null;
PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(project.getSchema());
if (oldLastRevision != null) {
int highestStopId = AbstractDownloadDatabaseAction.findHighestStopRid(project, oldLastRevision.getLastConcreteRevision());
OldQuery query = new OldQuery(longTransaction.getPackageMetaData(), project.getId(), oldLastRevision.getId(), -1, Deep.YES, highestStopId);
originalOidCounters = query.updateOidCounters(oldLastRevision.getLastConcreteRevision(), getDatabaseSession());
} else {
originalOidCounters = new OidCounters();
}
getDatabaseSession().addPostCommitAction(new PostCommitAction() {
@Override
public void execute() throws UserException {
getBimServer().getNotificationsManager().notify(new SConverter().convertToSObject(newRevisionAdded));
try {
getBimServer().getLongTransactionManager().remove(longTransaction.getTid());
} catch (NoTransactionException e) {
LOGGER.error("", e);
}
}
});
SummaryMap summaryMap = null;
if (oldLastRevision != null && oldLastRevision.getConcreteRevisions().size() == 1 && oldLastRevision.getConcreteRevisions().get(0).getSummary() != null) {
summaryMap = new SummaryMap(packageMetaData, oldLastRevision.getConcreteRevisions().get(0).getSummary());
} else {
summaryMap = new SummaryMap(packageMetaData);
}
// First create all new objects
Transaction transaction = new Transaction(getBimServer(), previousRevision, project, concreteRevision, getDatabaseSession());
for (Change change : longTransaction.getChanges()) {
if (change instanceof CreateObjectChange) {
try {
CreateObjectChange createObjectChange = (CreateObjectChange) change;
change.execute(transaction);
getDatabaseSession().addStartOid(createObjectChange.geteClass(), createObjectChange.getOid());
} catch (IOException | QueryException e) {
e.printStackTrace();
}
summaryMap.add(((CreateObjectChange) change).geteClass(), 1);
}
}
// Then do the rest
for (Change change : longTransaction.getChanges()) {
if (!(change instanceof CreateObjectChange)) {
if (change instanceof RemoveObjectChange) {
summaryMap.remove(((RemoveObjectChange) change).geteClass(), 1);
}
try {
change.execute(transaction);
} catch (IOException e) {
e.printStackTrace();
} catch (QueryException e) {
e.printStackTrace();
}
}
}
for (HashMapVirtualObject object : transaction.getCreated()) {
getDatabaseSession().save(object);
}
for (HashMapVirtualObject object : transaction.getUpdated()) {
getDatabaseSession().save(object, concreteRevision.getId());
}
for (HashMapVirtualObject object : transaction.getDeleted()) {
getDatabaseSession().delete(object, concreteRevision.getId());
}
setProgress("Generating inverses/opposites...", -1);
Revision newRevision = result.getRevisions().get(0);
long newRoid = newRevision.getOid();
try {
fixInverses(packageMetaData, newRoid, summaryMap.getSummaryMap());
} catch (QueryException | IOException e1) {
e1.printStackTrace();
}
int highestStopId = AbstractDownloadDatabaseAction.findHighestStopRid(concreteRevision.getProject(), concreteRevision);
QueryContext queryContext = new QueryContext(getDatabaseSession(), packageMetaData, project.getId(), concreteRevision.getId(), concreteRevision.getRevisions().get(0).getOid(), concreteRevision.getOid(), highestStopId);
Map<String, Long> startOids = getDatabaseSession().getStartOids();
if (startOids == null) {
throw new BimserverDatabaseException("No objects changed");
}
for (EClass eClass : packageMetaData.getEClasses()) {
if (startOids.containsKey(eClass.getEPackage().getName() + "." + eClass.getName())) {
long oid = startOids.get(eClass.getEPackage().getName() + "." + eClass.getName());
if (!DatabaseSession.perRecordVersioning(eClass)) {
originalOidCounters.putIfAbsent(eClass, oid);
}
}
}
queryContext.setOidCounters(originalOidCounters);
concreteRevision.setOidCounters(originalOidCounters == null ? null : originalOidCounters.getBytes());
if (getBimServer().getServerSettingsCache().getServerSettings().isGenerateGeometryOnCheckin()) {
if (regenerateAllGeometry) {
setProgress("Generating Geometry...", -1);
try {
GeometryGenerationReport report = new GeometryGenerationReport();
report.setOriginalDeserializer("No deserializer, low level call");
report.setOriginalIfcFileName("No file, low level call");
report.setOriginalIfcFileSize(-1);
StreamingGeometryGenerator streamingGeometryGenerator = new StreamingGeometryGenerator(getBimServer(), null, -1L, report);
GenerateGeometryResult generateGeometry = streamingGeometryGenerator.generateGeometry(authorization.getUoid(), getDatabaseSession(), queryContext, summaryMap.count());
concreteRevision.setMultiplierToMm(generateGeometry.getMultiplierToMm());
concreteRevision.setBounds(generateGeometry.getBounds());
concreteRevision.setBoundsUntransformed(generateGeometry.getBoundsUntransformed());
generateDensityAndBounds(result, generateGeometry, concreteRevision);
final GeometryGenerationReport finalReport = report;
getDatabaseSession().addPostCommitAction(new PostCommitAction() {
@Override
public void execute() throws UserException {
if (finalReport != null) {
byte[] htmlBytes = finalReport.toHtml().getBytes(Charsets.UTF_8);
byte[] jsonBytes = finalReport.toJson().toString().getBytes(Charsets.UTF_8);
try (DatabaseSession tmpSession = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE)) {
AddGeometryReports addGeometryReports = new AddGeometryReports(tmpSession, AccessMethod.INTERNAL, htmlBytes, jsonBytes, finalReport.getTimeToGenerateMs(), authorization.getUoid(), revision.getOid());
try {
tmpSession.executeAndCommitAction(addGeometryReports);
} catch (ServerException e1) {
LOGGER.error("", e1);
}
} catch (BimserverDatabaseException e1) {
LOGGER.error("", e1);
}
}
getBimServer().getNotificationsManager().notify(new NewRevisionNotification(getBimServer(), project.getOid(), revision.getOid(), authorization));
}
});
} catch (GeometryGeneratingException e) {
throw new UserException(e);
}
revision.setHasGeometry(true);
} else {
if (previousRevision != null) {
byte[] htmlBytes = null;
byte[] jsonBytes = null;
long timeToGenerate = -1;
for (ExtendedData previousExtendedData : previousRevision.getExtendedData()) {
ExtendedDataSchema previousSchema = previousExtendedData.getSchema();
if (previousSchema.getName().contentEquals("GEOMETRY_GENERATION_REPORT_HTML_1_1")) {
htmlBytes = previousExtendedData.getFile().getData();
} else if (previousSchema.getName().contentEquals("GEOMETRY_GENERATION_REPORT_JSON_1_1")) {
jsonBytes = previousExtendedData.getFile().getData();
}
}
byte[] finalHtmlBytes = htmlBytes;
byte[] finalJsonBytes = jsonBytes;
getDatabaseSession().addPostCommitAction(new PostCommitAction() {
public void execute() throws UserException {
try (DatabaseSession tmpSession = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE)) {
AddGeometryReports addGeometryReports = new AddGeometryReports(tmpSession, AccessMethod.INTERNAL, finalHtmlBytes, finalJsonBytes, timeToGenerate, authorization.getUoid(), revision.getOid());
try {
tmpSession.executeAndCommitAction(addGeometryReports);
} catch (ServerException e1) {
LOGGER.error("", e1);
}
} catch (BimserverDatabaseException e1) {
LOGGER.error("", e1);
}
}
});
concreteRevision.setMultiplierToMm(previousConcreteRevision.getMultiplierToMm());
concreteRevision.setBounds(previousConcreteRevision.getBounds());
concreteRevision.setBoundsUntransformed(previousConcreteRevision.getBoundsUntransformed());
newRevision.setBounds(previousRevision.getBounds());
newRevision.setBoundsUntransformed(previousRevision.getBoundsUntransformed());
newRevision.setBoundsMm(previousRevision.getBoundsMm());
newRevision.setBoundsUntransformedMm(previousRevision.getBoundsUntransformedMm());
// TODO validate this, contains ids?
newRevision.setDensityCollection(previousRevision.getDensityCollection());
revision.setHasGeometry(true);
}
}
}
concreteRevision.setSummary(summaryMap.toRevisionSummary(getDatabaseSession()));
getDatabaseSession().store(concreteRevision);
getDatabaseSession().store(project);
return concreteRevision;
}
Aggregations