use of org.bimserver.emf.IdEObject 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.emf.IdEObject in project BIMserver by opensourceBIM.
the class RevisionMerger method cleanupUnmodified.
@SuppressWarnings("rawtypes")
public void cleanupUnmodified() {
Iterator<Long> iterator = resultModel.keySet().iterator();
while (iterator.hasNext()) {
Long oid = iterator.next();
IdEObject idEObject = resultModel.get(oid);
IdEObject originalObject = oldModel.get(oid);
if (originalObject != null) {
boolean objectChanged = false;
for (EAttribute eAttribute : idEObject.eClass().getEAllAttributes()) {
Object value = idEObject.eGet(eAttribute);
Object originalValue = originalObject.eGet(eAttribute);
if (((value == null && originalValue != null) || (value != null && originalValue == null))) {
objectChanged = true;
continue;
}
if (!(value == null && originalValue == null) && !value.equals(originalValue)) {
objectChanged = true;
continue;
}
}
if (!objectChanged) {
for (EReference eReference : idEObject.eClass().getEAllReferences()) {
if (eReference.isMany()) {
List list = (List) idEObject.eGet(eReference);
List originalList = (List) originalObject.eGet(eReference);
if (list.size() != originalList.size()) {
objectChanged = true;
continue;
}
for (int i = 0; i < list.size(); i++) {
IdEObject referencedObject = (IdEObject) list.get(i);
IdEObject originalReferencedObject = (IdEObject) originalList.get(i);
if ((referencedObject == null && originalReferencedObject != null) || (referencedObject != null && originalReferencedObject == null)) {
objectChanged = true;
continue;
}
if (!(referencedObject == null && originalReferencedObject == null) && referencedObject.getOid() != originalReferencedObject.getOid()) {
objectChanged = true;
continue;
}
}
} else {
IdEObject referencedObject = (IdEObject) idEObject.eGet(eReference);
IdEObject originalReferencedObject = (IdEObject) originalObject.eGet(eReference);
if ((referencedObject == null && originalReferencedObject != null) || (referencedObject != null && originalReferencedObject == null)) {
objectChanged = true;
continue;
}
if (!(referencedObject == null && originalReferencedObject == null) && referencedObject.getOid() != originalReferencedObject.getOid()) {
objectChanged = true;
continue;
}
}
}
}
if (!objectChanged) {
iterator.remove();
}
}
}
}
use of org.bimserver.emf.IdEObject 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.emf.IdEObject 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);
}
}
}
}
}
}
}
}
}
use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class ReferenceCounter method updateReferences.
@SuppressWarnings("rawtypes")
public void updateReferences() {
references.clear();
for (IdEObject idEObject : ifcModel.getValues()) {
for (EReference eReference : idEObject.eClass().getEAllReferences()) {
if (eReference.isMany()) {
List list = (List) idEObject.eGet(eReference);
for (Object o : list) {
if (!references.containsKey(o)) {
references.put((IdEObject) o, new HashSet<Reference>());
}
references.get(o).add(new MultiReference(idEObject, (IdEObject) o, eReference));
}
} else {
Object o = idEObject.eGet(eReference);
if (!references.containsKey(o)) {
references.put((IdEObject) o, new HashSet<Reference>());
}
references.get(o).add(new SingleReference(idEObject, (IdEObject) o, eReference));
}
}
}
}
Aggregations