use of org.bimserver.models.ifc2x3tc1.IfcRoot in project BIMserver by opensourceBIM.
the class GetDataObjectsDatabaseAction method execute.
@Override
public List<DataObject> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
Revision virtualRevision = getRevisionByRoid(roid);
IfcModelSet ifcModelSet = new IfcModelSet();
PackageMetaData lastPackageMetaData = null;
Map<Integer, Long> pidRoidMap = new HashMap<>();
pidRoidMap.put(virtualRevision.getProject().getId(), virtualRevision.getOid());
for (ConcreteRevision concreteRevision : virtualRevision.getConcreteRevisions()) {
int highestStopId = findHighestStopRid(concreteRevision.getProject(), concreteRevision);
PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
lastPackageMetaData = packageMetaData;
IfcModel subModel = new ServerIfcModel(packageMetaData, pidRoidMap, getDatabaseSession());
OldQuery query = new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), virtualRevision.getOid(), null, Deep.YES, highestStopId);
getDatabaseSession().getMap(subModel, query);
subModel.getModelMetaData().setDate(concreteRevision.getDate());
ifcModelSet.add(subModel);
}
IfcModelInterface ifcModel = new ServerIfcModel(lastPackageMetaData, pidRoidMap, getDatabaseSession());
try {
ifcModel = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid()).merge(virtualRevision.getProject(), ifcModelSet, new ModelHelper(getBimServer().getMetaDataManager(), ifcModel));
} catch (MergeException e) {
throw new UserException(e);
}
List<DataObject> dataObjects = new ArrayList<DataObject>();
for (Long oid : ifcModel.keySet()) {
EObject eObject = ifcModel.get(oid);
if (eObject.eClass().getEAnnotation("hidden") == null) {
DataObject dataObject = null;
if (eObject instanceof IfcRoot) {
IfcRoot ifcRoot = (IfcRoot) eObject;
String guid = ifcRoot.getGlobalId() != null ? ifcRoot.getGlobalId() : "";
String name = ifcRoot.getName() != null ? ifcRoot.getName() : "";
dataObject = StoreFactory.eINSTANCE.createDataObject();
dataObject.setType(eObject.eClass().getName());
((IdEObjectImpl) dataObject).setOid(oid);
dataObject.setGuid(guid);
dataObject.setName(name);
} else {
dataObject = StoreFactory.eINSTANCE.createDataObject();
dataObject.setType(eObject.eClass().getName());
((IdEObjectImpl) dataObject).setOid(oid);
dataObject.setGuid("");
dataObject.setName("");
}
GetDataObjectByOidDatabaseAction.fillDataObject(ifcModel.getObjects(), eObject, dataObject);
dataObjects.add(dataObject);
}
}
return dataObjects;
}
use of org.bimserver.models.ifc2x3tc1.IfcRoot in project BIMserver by opensourceBIM.
the class TestSetString method test.
@Test
public void test() {
try {
BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
bimServerClient.getSettingsInterface().setCacheOutputFiles(false);
LowLevelInterface lowLevelInterface = bimServerClient.getLowLevelInterface();
SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
SDeserializerPluginConfiguration suggestedDeserializerForExtension = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
bimServerClient.checkin(newProject.getOid(), "initial", suggestedDeserializerForExtension.getOid(), false, Flow.SYNC, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/WallOnly.ifc"));
newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
SSerializerPluginConfiguration serializer = bimServerClient.getServiceInterface().getSerializerByName("Ifc2x3tc1 (Streaming)");
bimServerClient.download(newProject.getLastRevisionId(), serializer.getOid(), Paths.get("test1.ifc"));
IfcModelInterface model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), true, false);
long tid = lowLevelInterface.startTransaction(newProject.getOid());
IfcRoot wall = (IfcRoot) model.getByGuid("3Ep4r0uuX5ywPYOUG2H2A4");
bimServerClient.getLowLevelInterface().setStringAttribute(tid, wall.getOid(), "Name", "Test 12345");
long roid = lowLevelInterface.commitTransaction(tid, "v2");
bimServerClient.download(roid, serializer.getOid(), Paths.get("test3.ifc"));
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.bimserver.models.ifc2x3tc1.IfcRoot in project BIMserver by opensourceBIM.
the class RevisionMerger method copyAttributesGuidObjectsAndAddNewObjects.
private void copyAttributesGuidObjectsAndAddNewObjects() throws IfcModelInterfaceException, ObjectAlreadyExistsException {
for (IdEObject idEObject : newModel.getValues()) {
if (idEObject instanceof IfcRoot) {
IfcRoot ifcRoot = (IfcRoot) idEObject;
String guid = ifcRoot.getGlobalId();
if (resultModel.containsGuid(guid)) {
// LOGGER.info("Updating attributes for object " + idEObject.eClass().getName() + " " + guid);
IfcRoot oldObject = (IfcRoot) resultModel.getByGuid(guid);
for (EAttribute eAttribute : idEObject.eClass().getEAllAttributes()) {
Object newValue = idEObject.eGet(eAttribute);
oldObject.eSet(eAttribute, newValue);
}
} else {
// LOGGER.info("Adding new GUID object " + idEObject.eClass().getName() + " " + guid);
IdEObject newObject = (IdEObject) idEObject.eClass().getEPackage().getEFactoryInstance().create(idEObject.eClass());
((IdEObjectImpl) newObject).setOid(idEObject.getOid());
((IfcRoot) newObject).setGlobalId(newGuid(guid));
for (EAttribute eAttribute : newObject.eClass().getEAllAttributes()) {
newObject.eSet(eAttribute, idEObject.eGet(eAttribute));
}
resultModel.add(newObject.getOid(), newObject);
}
}
}
}
use of org.bimserver.models.ifc2x3tc1.IfcRoot in project BIMserver by opensourceBIM.
the class RevisionMerger method updateReferences.
@SuppressWarnings({ "unchecked", "rawtypes" })
private void updateReferences() {
for (IdEObject idEObject : newModel.getValues()) {
if (idEObject instanceof IfcRoot) {
String guid = ((IfcRoot) idEObject).getGlobalId();
IfcRoot oldObject = (IfcRoot) resultModel.getByGuid(guid);
for (EReference eReference : idEObject.eClass().getEAllReferences()) {
Object referencedObject = idEObject.eGet(eReference);
if (referencedObject instanceof IfcRoot) {
String referencedGuid = ((IfcRoot) referencedObject).getGlobalId();
IfcRoot newObject = (IfcRoot) resultModel.getByGuid(referencedGuid);
oldObject.eSet(eReference, newObject);
// LOGGER.info("Fixing reference from " + guid + " to " + referencedGuid);
} else if (referencedObject instanceof List) {
List referencedList = (List) referencedObject;
List oldReferencedList = (List) oldObject.eGet(eReference);
for (Object object : referencedList) {
if (object instanceof IfcRoot) {
IfcRoot referencedItem = (IfcRoot) object;
String itemGuid = referencedItem.getGlobalId();
oldReferencedList.add(resultModel.getByGuid(itemGuid));
// LOGGER.info("Fixing list reference from " + guid + " to " + itemGuid);
}
}
}
}
}
}
}
use of org.bimserver.models.ifc2x3tc1.IfcRoot in project BIMserver by opensourceBIM.
the class RevisionMerger method fixExplicitNullReferences.
@SuppressWarnings({ "unchecked", "rawtypes" })
private void fixExplicitNullReferences() {
for (IdEObject idEObject : newModel.getValues()) {
if (idEObject instanceof IfcRoot) {
String guid = ((IfcRoot) idEObject).getGlobalId();
for (EReference eReference : idEObject.eClass().getEAllReferences()) {
if (eReference.isMany()) {
List list = (List) idEObject.eGet(eReference);
List oldList = (List) resultModel.getByGuid(guid).eGet(eReference);
Set<Object> guidsToRemove = new HashSet<Object>();
for (Object o : oldList) {
if (o instanceof IfcRoot) {
String referredGuid = ((IfcRoot) o).getGlobalId();
if (newModel.containsGuid(referredGuid)) {
boolean found = false;
for (Object q : list) {
if (q instanceof IfcRoot) {
String qGuid = ((IfcRoot) q).getGlobalId();
if (qGuid.equals(referredGuid)) {
found = true;
break;
}
}
}
if (!found) {
guidsToRemove.add(referredGuid);
}
}
}
}
if (!guidsToRemove.isEmpty()) {
// LOGGER.info("Removing list references");
oldList.removeAll(guidsToRemove);
}
} else {
if (idEObject.eGet(eReference) == null) {
Object eGet = resultModel.getByGuid(guid).eGet(eReference);
if (eGet != null) {
if (eGet instanceof IfcRoot) {
String oldGuid = ((IfcRoot) eGet).getGlobalId();
if (newModel.containsGuid(oldGuid)) {
// LOGGER.info("Settings explicit null reference");
resultModel.getByGuid(guid).eSet(eReference, null);
}
}
}
}
}
}
}
}
}
Aggregations