use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class RevisionMerger method fixNonGuidObjects.
@SuppressWarnings({ "rawtypes", "unchecked" })
private void fixNonGuidObjects() throws IfcModelInterfaceException {
Set<List> clearedLists = new HashSet<List>();
for (IdEObject idEObject : newModel.getValues()) {
if (idEObject instanceof IfcRoot) {
String guid = ((IfcRoot) idEObject).getGlobalId();
for (EReference eReference : idEObject.eClass().getEAllReferences()) {
Object referencedObject = idEObject.eGet(eReference);
if (eReference.isMany()) {
List list = (List) referencedObject;
List newList = (List) resultModel.getByGuid(guid).eGet(eReference);
boolean listIsCleared = false;
for (Object o : list) {
if (!(o instanceof IfcRoot) && !(o instanceof IfcGloballyUniqueId)) {
if (!listIsCleared) {
newList.clear();
listIsCleared = true;
}
IdEObject referencedIDEObject = (IdEObject) o;
if (resultModel.contains(referencedIDEObject.getOid())) {
newList.add(resultModel.get(referencedIDEObject.getOid()));
} else {
IdEObject smartCopy = copy(resultModel, referencedIDEObject, true);
newList.add(smartCopy);
}
}
}
} else {
if (referencedObject == null) {
if (resultModel.getByGuid(guid).eGet(eReference) != null && eReference.getEOpposite() != null) {
IdEObject x = (IdEObject) resultModel.getByGuid(guid).eGet(eReference);
if (eReference.getEOpposite().isMany()) {
List l = (List) x.eGet(eReference.getEOpposite());
if (!clearedLists.contains(l)) {
clearedLists.add(l);
l.clear();
}
} else {
x.eSet(eReference.getEOpposite(), null);
}
}
resultModel.getByGuid(guid).eSet(eReference, null);
} else {
if (!(referencedObject instanceof IfcRoot) && !(referencedObject instanceof IfcGloballyUniqueId)) {
IdEObject referencedIDEObject = (IdEObject) referencedObject;
if (resultModel.contains(referencedIDEObject.getOid())) {
if (resultModel.getByGuid(guid).eGet(eReference) != null && eReference.getEOpposite() != null) {
IdEObject x = (IdEObject) resultModel.getByGuid(guid).eGet(eReference);
if (eReference.getEOpposite().isMany()) {
List l = (List) x.eGet(eReference.getEOpposite());
if (!clearedLists.contains(l)) {
clearedLists.add(l);
l.clear();
}
} else {
x.eSet(eReference.getEOpposite(), null);
}
}
resultModel.getByGuid(guid).eSet(eReference, resultModel.get(referencedIDEObject.getOid()));
} else {
IdEObject smartCopy = copy(resultModel, referencedIDEObject, true);
if (resultModel.getByGuid(guid).eGet(eReference) != null && eReference.getEOpposite() != null) {
IdEObject re = (IdEObject) resultModel.getByGuid(guid).eGet(eReference);
if (eReference.getEOpposite().isMany()) {
List l = (List) re.eGet(eReference.getEOpposite());
if (!clearedLists.contains(l)) {
clearedLists.add(l);
l.clear();
}
} else {
re.eSet(eReference.getEOpposite(), null);
}
}
resultModel.getByGuid(guid).eSet(eReference, smartCopy);
}
}
}
}
}
}
}
}
use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class RevisionMerger method copy.
@SuppressWarnings({ "unchecked", "rawtypes" })
private IdEObject copy(IfcModel target, IdEObject idEObject, boolean limitToNonGuids) throws IfcModelInterfaceException {
if (target.contains(idEObject.getOid())) {
return target.get(idEObject.getOid());
}
IdEObject newObject = (IdEObject) idEObject.eClass().getEPackage().getEFactoryInstance().create(idEObject.eClass());
((IdEObjectImpl) newObject).setOid(idEObject.getOid());
if (newObject.getOid() != -1) {
target.add(newObject.getOid(), newObject);
}
for (EAttribute eAttribute : newObject.eClass().getEAllAttributes()) {
newObject.eSet(eAttribute, idEObject.eGet(eAttribute));
}
for (EReference eReference : newObject.eClass().getEAllReferences()) {
Object referencedObject = idEObject.eGet(eReference);
if (referencedObject instanceof IdEObject) {
IdEObject refEObject = (IdEObject) referencedObject;
if (!limitToNonGuids || !(referencedObject instanceof IfcRoot) && !(referencedObject instanceof IfcGloballyUniqueId)) {
newObject.eSet(eReference, copy(target, refEObject, limitToNonGuids));
}
} else if (referencedObject instanceof List) {
List list = (List) referencedObject;
List newList = (List) newObject.eGet(eReference);
for (Object o : list) {
if (!limitToNonGuids || !(o instanceof IfcRoot) && !(o instanceof IfcGloballyUniqueId)) {
IdEObject listObject = (IdEObject) o;
IdEObject smartCopy = copy(target, listObject, limitToNonGuids);
if (!newList.contains(smartCopy)) {
newList.add(smartCopy);
}
}
}
}
}
return newObject;
}
use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class AbstractSchemaConverter method copy.
@SuppressWarnings("unchecked")
protected IdEObject copy(IdEObject original) throws IfcModelInterfaceException, ObjectAlreadyExistsException {
if (!((IdEObjectImpl) original).isLoadedOrLoading()) {
return null;
}
if (converted.containsKey(original)) {
return converted.get(original);
}
if (original.eClass().getName().equals("GeometryInfo") || original.eClass().getName().equals("GeometryData") || original.eClass().getName().equals("Vector3f")) {
return null;
}
EClass eClass = (EClass) target.getPackageMetaData().getEPackage().getEClassifier(original.eClass().getName());
if (eClass == null) {
LOGGER.info("No class " + original.eClass().getName() + " in " + target.getPackageMetaData().getEPackage().getName());
return null;
}
IdEObject newObject = (IdEObject) eClass.getEPackage().getEFactoryInstance().create(eClass);
((IdEObjectImpl) newObject).setOid(original.getOid());
converted.put(original, newObject);
if (newObject.eClass().getEAnnotation("wrapped") == null) {
target.add(newObject.getOid(), newObject);
}
for (EStructuralFeature eStructuralFeature : original.eClass().getEAllStructuralFeatures()) {
EStructuralFeature targetFeature = newObject.eClass().getEStructuralFeature(eStructuralFeature.getName());
if (targetFeature == null) {
continue;
}
Object get = original.eGet(eStructuralFeature);
if (eStructuralFeature instanceof EAttribute) {
if (get instanceof Double) {
EStructuralFeature doubleStringFeature = original.eClass().getEStructuralFeature("wrappedValueAsString");
EStructuralFeature targetDoubleStringFeature = newObject.eClass().getEStructuralFeature("wrappedValueAsString");
if (doubleStringFeature != null && targetDoubleStringFeature != null) {
Object doubleString = original.eGet(doubleStringFeature);
newObject.eSet(targetDoubleStringFeature, doubleString);
} else {
newObject.eSet(targetFeature, get);
}
} else {
if (eStructuralFeature.getEType() instanceof EEnum) {
EEnum targetEnum = (EEnum) targetFeature.getEType();
EEnumLiteral newLiteral = targetEnum.getEEnumLiteral(get.toString());
if (newLiteral != null) {
newObject.eSet(targetFeature, newLiteral.getInstance());
}
} else {
if (targetFeature instanceof EAttribute) {
newObject.eSet(targetFeature, get);
}
}
}
} else if (eStructuralFeature instanceof EReference) {
if (get == null) {
} else {
if (eStructuralFeature.isMany()) {
EList<EObject> list = (EList<EObject>) get;
AbstractEList<EObject> toList = (AbstractEList<EObject>) newObject.eGet(targetFeature);
if (toList != null) {
for (Object o : list) {
IdEObject ref = (IdEObject) o;
if (targetFeature.getEType().isInstance(ref)) {
if (converted.containsKey(o)) {
toList.addUnique(converted.get(o));
} else {
IdEObject result = copy((IdEObject) o);
if (result != null) {
toList.addUnique(result);
}
}
}
}
}
} else {
if (targetFeature.isMany()) {
LOGGER.info("Different multiplicity");
} else {
if (converted.containsKey(get)) {
newObject.eSet(targetFeature, converted.get(get));
} else {
newObject.eSet(targetFeature, copy((IdEObject) get));
}
}
}
}
}
}
return newObject;
}
use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class GetAllWritableProjectsDatabaseAction method execute.
@Override
public Set<Project> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
User user = getUserByUoid(authorization.getUoid());
IfcModelInterface projectsModel = getDatabaseSession().getAllOfType(StorePackage.eINSTANCE.getProject(), OldQuery.getDefault());
Set<Project> result = new HashSet<Project>();
for (IdEObject idEObject : projectsModel.getValues()) {
if (idEObject instanceof Project) {
Project project = (Project) idEObject;
if (!project.getName().equals("INT-Store")) {
if ((user.getUserType() == UserType.ADMIN || (project.getState() == ObjectState.ACTIVE) && authorization.hasRightsOnProjectOrSuperProjects(user, project))) {
result.add(project);
}
}
}
}
return result;
}
use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class GetDataObjectByOidDatabaseAction method fillDataObject.
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void fillDataObject(BiMap<? extends Long, ? extends EObject> mapResult, EObject eObject, DataObject dataObject) {
for (EStructuralFeature eStructuralFeature : eObject.eClass().getEAllStructuralFeatures()) {
Object eGet = eObject.eGet(eStructuralFeature);
if (eStructuralFeature.getEAnnotation("hidden") == null) {
if (eStructuralFeature instanceof EAttribute) {
if (eStructuralFeature.isMany()) {
ListDataValue listDataValue = StoreFactory.eINSTANCE.createListDataValue();
listDataValue.setFieldName(eStructuralFeature.getName());
dataObject.getValues().add(listDataValue);
if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDoubleObject() || eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDouble()) {
EStructuralFeature asStringFeature = eObject.eClass().getEStructuralFeature(eStructuralFeature.getName() + "AsString");
List list = (List) eObject.eGet(asStringFeature);
for (Object o : list) {
SimpleDataValue dataValue = StoreFactory.eINSTANCE.createSimpleDataValue();
dataValue.setStringValue(o.toString());
listDataValue.getValues().add(dataValue);
}
} else {
if (eGet != null) {
List list = (List) eGet;
for (Object o : list) {
SimpleDataValue dataValue = StoreFactory.eINSTANCE.createSimpleDataValue();
if (eGet != null) {
dataValue.setStringValue(o.toString());
} else {
dataValue.setStringValue(null);
}
listDataValue.getValues().add(dataValue);
}
}
}
} else {
SimpleDataValue dataValue = StoreFactory.eINSTANCE.createSimpleDataValue();
if (eObject.eIsSet(eStructuralFeature)) {
if (eGet instanceof byte[]) {
dataValue.setStringValue(new String(((byte[]) eGet), Charsets.UTF_8));
} else {
dataValue.setStringValue(eGet.toString());
}
} else {
dataValue.setStringValue(null);
}
dataValue.setFieldName(eStructuralFeature.getName());
dataObject.getValues().add(dataValue);
}
} else if (eStructuralFeature instanceof EReference) {
if (eStructuralFeature.isMany()) {
if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDouble() || eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDoubleObject()) {
List list = (List) eObject.eGet(eObject.eClass().getEStructuralFeature(eStructuralFeature.getName() + "AsString"));
ListDataValue dataValue = StoreFactory.eINSTANCE.createListDataValue();
dataValue.setFieldName(eStructuralFeature.getName());
dataObject.getValues().add(dataValue);
for (Object o : list) {
SimpleDataValue simpleDataValue = StoreFactory.eINSTANCE.createSimpleDataValue();
simpleDataValue.setStringValue(o.toString());
dataValue.getValues().add(simpleDataValue);
}
} else {
EList<? extends EObject> list = (EList<EObject>) eGet;
ListDataValue dataValue = StoreFactory.eINSTANCE.createListDataValue();
dataObject.getValues().add(dataValue);
dataValue.setFieldName(eStructuralFeature.getName());
for (EObject item : list) {
if (item.eClass().getEAnnotation("wrapped") != null) {
EObject referenceEObject = item;
SimpleDataValue simpleDataValue = StoreFactory.eINSTANCE.createSimpleDataValue();
simpleDataValue.setStringValue(referenceEObject.eGet(referenceEObject.eClass().getEStructuralFeature("wrappedValue")).toString());
dataValue.getValues().add(simpleDataValue);
} else {
Long oid = ((IdEObject) item).getOid();
ReferenceDataValue referenceDataValue = StoreFactory.eINSTANCE.createReferenceDataValue();
if (item instanceof IfcRoot) {
IfcRoot ifcRoot = (IfcRoot) item;
String guid = ifcRoot.getGlobalId();
referenceDataValue.setGuid(guid);
}
referenceDataValue.setTypeName(item.eClass().getName());
((IdEObjectImpl) referenceDataValue).setOid(oid);
dataValue.getValues().add(referenceDataValue);
}
}
}
} else {
EObject eObject2 = (EObject) eGet;
if (eObject2 != null) {
if (eObject2.eClass().getEAnnotation("wrapped") != null) {
EObject referenceEObject = (EObject) eGet;
SimpleDataValue e = StoreFactory.eINSTANCE.createSimpleDataValue();
EStructuralFeature wrappedValueFeature = referenceEObject.eClass().getEStructuralFeature("wrappedValue");
Object eGet2 = referenceEObject.eGet(wrappedValueFeature);
// } else {
if (eGet2 != null) {
e.setStringValue(eGet2.toString());
} else {
e.setStringValue(null);
}
// }
e.setFieldName(eStructuralFeature.getName());
dataObject.getValues().add(e);
} else {
Long oid = ((IdEObject) eObject2).getOid();
ReferenceDataValue reference = StoreFactory.eINSTANCE.createReferenceDataValue();
if (eObject2 instanceof IfcRoot) {
IfcRoot ifcRoot = (IfcRoot) eObject2;
String guid = ifcRoot.getGlobalId();
reference.setGuid(guid);
}
reference.setTypeName(eObject2.eClass().getName());
((IdEObjectImpl) reference).setOid(oid);
reference.setFieldName(eStructuralFeature.getName());
dataObject.getValues().add(reference);
}
}
}
}
}
}
}
Aggregations