use of org.eclipse.emf.ecore.EReference in project BIMserver by opensourceBIM.
the class Express2EMF method doRealDerivedAttributes.
private void doRealDerivedAttributes() {
for (EntityDefinition entityDefinition : schema.getEntities()) {
for (DerivedAttribute2 attributeName : entityDefinition.getDerivedAttributes().values()) {
EClass eClass = (EClass) schemaPack.getEClassifier(entityDefinition.getName());
// eFactory.createEReference();
if (attributeName.getType() != null && !attributeName.hasSuper()) {
// derivedAttribute.setEType(schemaPack.getEClassifier("IfcLogical"));
if (attributeName.getType() instanceof DefinedType) {
EClassifier eType = schemaPack.getEClassifier(((DefinedType) attributeName.getType()).getName());
boolean found = false;
for (EClass eSuperType : eClass.getEAllSuperTypes()) {
if (eSuperType.getEStructuralFeature(attributeName.getName()) != null) {
found = true;
break;
}
}
if (eType.getEAnnotation("wrapped") != null) {
if (!found) {
EAttribute eAttribute = eFactory.createEAttribute();
eAttribute.setDerived(true);
eAttribute.setName(attributeName.getName());
if (eAttribute.getName().equals("RefLatitude") || eAttribute.getName().equals("RefLongitude")) {
eAttribute.setUpperBound(3);
eAttribute.setUnique(false);
}
EClassifier type = ((EClass) eType).getEStructuralFeature("wrappedValue").getEType();
eAttribute.setEType(type);
// TODO find out
eAttribute.setUnsettable(true);
// if its
// optional
eClass.getEStructuralFeatures().add(eAttribute);
if (type == EcorePackage.eINSTANCE.getEDouble()) {
EAttribute doubleStringAttribute = eFactory.createEAttribute();
doubleStringAttribute.setName(attributeName.getName() + "AsString");
doubleStringAttribute.getEAnnotations().add(createAsStringAnnotation());
doubleStringAttribute.getEAnnotations().add(createHiddenAnnotation());
// TODO
doubleStringAttribute.setUnsettable(true);
// find
// out
// if
// its
// optional
doubleStringAttribute.setEType(EcorePackage.eINSTANCE.getEString());
eClass.getEStructuralFeatures().add(doubleStringAttribute);
}
}
} else {
if (!found) {
EReference eReference = eFactory.createEReference();
eReference.setName(attributeName.getName());
eReference.setDerived(true);
eReference.setUnsettable(true);
eReference.setEType(eType);
eClass.getEStructuralFeatures().add(eReference);
}
}
// derivedAttribute.setEType(eType);
}
}
// derivedAttribute.setName(attributeName.getName());
// derivedAttribute.setDerived(true);
// derivedAttribute.setTransient(true);
// derivedAttribute.setVolatile(true);
// if (attributeName.isCollection()) {
// derivedAttribute.setUpperBound(-1);
// }
// EAnnotation annotation = eFactory.createEAnnotation();
// annotation.setSource("http://www.iso.org/iso10303-11/EXPRESS");
// annotation.getDetails().put("code",
// attributeName.getExpressCode());
// derivedAttribute.getEAnnotations().add(annotation);
// if (eClass.getEStructuralFeature(derivedAttribute.getName())
// == null) {
// eClass.getEStructuralFeatures().add(derivedAttribute);
// }
}
}
}
use of org.eclipse.emf.ecore.EReference in project BIMserver by opensourceBIM.
the class Express2EMF method addTwoDimensionalArray.
private void addTwoDimensionalArray(String entityName, String attribName) {
EClassifier finalType = null;
if (entityName.equals("IfcBSplineSurface") && attribName.equals("ControlPointsList")) {
finalType = schemaPack.getEClassifier("IfcCartesianPoint");
} else if (entityName.equals("IfcCartesianPointList3D") && attribName.equals("CoordList")) {
finalType = schemaPack.getEClassifier("IfcLengthMeasure");
} else if (entityName.equals("IfcColourRgbList") && attribName.equals("ColourList")) {
finalType = schemaPack.getEClassifier("IfcNormalisedRatioMeasure");
} else if (entityName.equals("IfcIndexedTriangleTextureMap") && attribName.equals("TexCoordIndex")) {
finalType = EcorePackage.eINSTANCE.getELong();
} else if (entityName.equals("IfcRationalBSplineSurfaceWithKnots") && attribName.equals("WeightsData")) {
finalType = EcorePackage.eINSTANCE.getEDouble();
} else if (entityName.equals("IfcStructuralLoadConfiguration") && attribName.equals("Locations")) {
finalType = schemaPack.getEClassifier("IfcLengthMeasure");
} else if (entityName.equals("IfcTessellatedFaceSet") && attribName.equals("Normals")) {
finalType = schemaPack.getEClassifier("IfcParameterValue");
} else if (entityName.equals("IfcTextureVertexList") && attribName.equals("TexCoordsList")) {
finalType = schemaPack.getEClassifier("IfcParameterValue");
} else if (entityName.equals("IfcTriangulatedFaceSet") && attribName.equals("CoordIndex")) {
finalType = EcorePackage.eINSTANCE.getELong();
} else if (entityName.equals("IfcCartesianPointList2D") && attribName.equals("CoordList")) {
finalType = schemaPack.getEClassifier("IfcCartesianPoint");
} else if (entityName.equals("IfcIndexedPolygonalFaceWithVoids") && attribName.equals("InnerCoordIndices")) {
finalType = EcorePackage.eINSTANCE.getELong();
} else if (entityName.equals("IfcTriangulatedFaceSet") && attribName.equals("Normals")) {
finalType = schemaPack.getEClassifier("IfcParameterValue");
} else if (entityName.equals("IfcTriangulatedFaceSet") && attribName.equals("NormalIndex")) {
finalType = EcorePackage.eINSTANCE.getELong();
} else {
throw new RuntimeException("Unimplemented " + entityName + "." + attribName);
}
EClass containerClass = (EClass) schemaPack.getEClassifier("ListOf" + finalType.getName());
if (containerClass == null) {
containerClass = EcoreFactory.eINSTANCE.createEClass();
containerClass.setName("ListOf" + finalType.getName());
if (finalType.getEPackage() == EcorePackage.eINSTANCE) {
EAttribute finalAttribute = EcoreFactory.eINSTANCE.createEAttribute();
finalAttribute.setName("List");
finalAttribute.setEType(finalType);
finalAttribute.setUpperBound(-1);
containerClass.getEAttributes().add(finalAttribute);
} else {
EReference finalReference = EcoreFactory.eINSTANCE.createEReference();
finalReference.setName("List");
finalReference.setEType(finalType);
finalReference.setUpperBound(-1);
containerClass.getEReferences().add(finalReference);
}
schemaPack.getEClassifiers().add(containerClass);
}
EReference eReference = EcoreFactory.eINSTANCE.createEReference();
eReference.getEAnnotations().add(createTwoDimensionalArrayAnnotation());
eReference.setName(attribName);
eReference.setUpperBound(-1);
eReference.setEType(containerClass);
EClass cls = (EClass) schemaPack.getEClassifier(entityName);
cls.getEStructuralFeatures().add(eReference);
}
use of org.eclipse.emf.ecore.EReference in project BIMserver by opensourceBIM.
the class ObjectInfoSerializer method writeTable.
@SuppressWarnings("unchecked")
private void writeTable(PrintWriter out, EObject eObject) {
out.println("<h1>" + eObject.eClass().getName() + "</h1>");
out.println("<table>");
for (EStructuralFeature eStructuralFeature : eObject.eClass().getEAllStructuralFeatures()) {
if (eStructuralFeature.getEAnnotation("hidden") == null) {
out.println("<tr>");
out.println("<td>" + eStructuralFeature.getName() + "</td>");
Object eGet = eObject.eGet(eStructuralFeature);
if (eStructuralFeature instanceof EAttribute) {
if (eStructuralFeature.getUpperBound() == 1) {
out.println("<td>" + eGet + "</td>");
} else {
List<Object> list = (List<Object>) eGet;
out.println("<td>");
for (Object object : list) {
out.println(object + " ");
}
out.println("</td>");
}
} else if (eStructuralFeature instanceof EReference) {
if (eStructuralFeature.getUpperBound() == 1) {
if (eStructuralFeature.getEType().getEAnnotation("wrapped") != null) {
EObject value = (EObject) eGet;
if (value != null) {
out.println("<td>" + value.eGet(value.eClass().getEStructuralFeature("wrappedValue")) + "</td>");
}
} else {
}
} else {
if (eStructuralFeature.getEType().getEAnnotation("wrapped") != null) {
List<EObject> list = (List<EObject>) eGet;
out.println("<td>");
for (EObject object : list) {
out.println("<td>" + object.eGet(object.eClass().getEStructuralFeature("wrappedValue")) + "</td>");
}
out.println("</td>");
} else {
}
}
}
}
out.println("</tr>");
}
out.println("</table>");
}
use of org.eclipse.emf.ecore.EReference in project BIMserver by opensourceBIM.
the class ClientIfcModel method branch.
@SuppressWarnings({ "unchecked", "rawtypes" })
public ClientIfcModel branch(long poid, boolean recordChanges) {
// TODO this should of course be done server side, without any copying
ClientIfcModel branch = new ClientIfcModel(bimServerClient, getPackageMetaData(), poid, recordChanges);
try {
loadDeep();
} catch (ServerException e) {
LOGGER.error("", e);
} catch (UserException e) {
LOGGER.error("", e);
} catch (PublicInterfaceNotFoundException e) {
LOGGER.error("", e);
} catch (QueryException e) {
LOGGER.error("", e);
}
Map<IdEObject, IdEObject> map = new HashMap<IdEObject, IdEObject>();
for (IdEObject sourceObject : getValues()) {
try {
IdEObjectImpl targetObject = branch.create(sourceObject.eClass());
targetObject.setLoadingState(State.LOADED);
map.put(sourceObject, targetObject);
} catch (IfcModelInterfaceException e) {
LOGGER.error("", e);
}
}
for (IdEObject sourceObject : getObjects().values()) {
IdEObject targetObject = map.get(sourceObject);
for (EStructuralFeature eStructuralFeature : sourceObject.eClass().getEAllStructuralFeatures()) {
Object sourceValue = sourceObject.eGet(eStructuralFeature);
if (eStructuralFeature instanceof EReference) {
if (eStructuralFeature.isMany()) {
List sourceList = (List) sourceValue;
List targetList = (List) targetObject.eGet(eStructuralFeature);
for (Object sourceItem : sourceList) {
IdEObject e = map.get(sourceItem);
if (e != null) {
targetList.add(e);
}
}
} else {
targetObject.eSet(eStructuralFeature, map.get(sourceValue));
}
} else {
if (eStructuralFeature.isMany()) {
List sourceList = (List) sourceValue;
List targetList = (List) targetObject.eGet(eStructuralFeature);
for (Object sourceItem : sourceList) {
targetList.add(sourceItem);
}
} else {
targetObject.eSet(eStructuralFeature, sourceValue);
}
}
}
}
branch.setModelState(ModelState.FULLY_LOADED);
return branch;
}
use of org.eclipse.emf.ecore.EReference in project BIMserver by opensourceBIM.
the class DownloadByNewJsonQueryDatabaseAction method execute.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public IfcModelInterface execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
List<String> projectNames = new ArrayList<>();
setProgress("Querying database...", -1);
for (long roid : roids) {
Revision revision = getDatabaseSession().get(StorePackage.eINSTANCE.getRevision(), roid, OldQuery.getDefault());
projectNames.add(revision.getProject().getName() + "." + revision.getId());
}
String name = Joiner.on("-").join(projectNames);
PackageMetaData lastPackageMetaData = null;
Project lastProject = null;
IfcModelSet ifcModelSet = new IfcModelSet();
Map<Integer, Long> pidRoidMap = new HashMap<>();
for (long roid : roids) {
Revision revision = getDatabaseSession().get(StorePackage.eINSTANCE.getRevision(), roid, OldQuery.getDefault());
lastProject = revision.getProject();
PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(revision.getProject().getSchema());
lastPackageMetaData = packageMetaData;
JsonQueryObjectModelConverter converter = new JsonQueryObjectModelConverter(packageMetaData);
ObjectNode queryObject;
try {
queryObject = OBJECT_MAPPER.readValue(json, ObjectNode.class);
Query query = converter.parseJson("query", (ObjectNode) queryObject);
pidRoidMap.put(revision.getProject().getId(), roid);
IfcModelInterface ifcModel = new ServerIfcModel(packageMetaData, pidRoidMap, getDatabaseSession());
ifcModelSet.add(ifcModel);
QueryObjectProvider queryObjectProvider = new QueryObjectProvider(getDatabaseSession(), getBimServer(), query, Collections.singleton(roid), packageMetaData);
HashMapVirtualObject next = queryObjectProvider.next();
while (next != null) {
IdEObject newObject = packageMetaData.create(next.eClass());
IdEObjectImpl idEObjectImpl = (IdEObjectImpl) newObject;
idEObjectImpl.setPid(revision.getProject().getId());
idEObjectImpl.setOid(next.getOid());
for (EAttribute eAttribute : newObject.eClass().getEAllAttributes()) {
Object value = next.eGet(eAttribute);
if (eAttribute.isMany()) {
List<?> list = (List<?>) value;
if (list != null) {
AbstractEList targetList = (AbstractEList) newObject.eGet(eAttribute);
for (Object item : list) {
targetList.addUnique(item);
}
}
} else {
if (value != null || eAttribute.isUnsettable()) {
newObject.eSet(eAttribute, value);
}
}
}
ifcModel.add(next.getOid(), newObject);
next = queryObjectProvider.next();
}
queryObjectProvider = new QueryObjectProvider(getDatabaseSession(), getBimServer(), query, Collections.singleton(roid), packageMetaData);
next = queryObjectProvider.next();
while (next != null) {
IdEObject idEObject = ifcModel.get(next.getOid());
if (idEObject.eClass() != next.eClass()) {
// Something is wrong
throw new RuntimeException("Classes not the same");
}
for (EReference eReference : idEObject.eClass().getEAllReferences()) {
if (eReference.isMany()) {
List refOids = (List) next.eGet(eReference);
AbstractEList<IdEObject> list = (AbstractEList<IdEObject>) idEObject.eGet(eReference);
if (refOids != null) {
for (Object refOid : refOids) {
if (refOid instanceof Long) {
IdEObject ref = ifcModel.get((long) refOid);
if (ref != null) {
if (eReference.isUnique()) {
list.add(ref);
} else {
list.addUnique(ref);
}
}
} else if (refOid instanceof HashMapWrappedVirtualObject) {
// IdEObject ref = ifcModel.get(((HashMapWrappedVirtualObject) refOid).get);
// if (ref != null) {
// list.add(ref);
// }
} else if (refOid instanceof HashMapVirtualObject) {
HashMapVirtualObject hashMapVirtualObject = (HashMapVirtualObject) refOid;
IdEObject listObject = packageMetaData.create(hashMapVirtualObject.eClass());
List subList = (List<?>) hashMapVirtualObject.get("List");
List newList = (List<?>) listObject.eGet(listObject.eClass().getEStructuralFeature("List"));
for (Object o : subList) {
if (o instanceof HashMapWrappedVirtualObject) {
newList.add(convertWrapped(revision, ifcModel, (HashMapWrappedVirtualObject) o));
} else {
newList.add(o);
}
}
list.addUnique(listObject);
} else {
}
}
}
} else {
Object r = next.eGet(eReference);
if (r instanceof Long) {
long refOid = (Long) r;
idEObject.eSet(eReference, ifcModel.get(refOid));
} else if (r instanceof HashMapWrappedVirtualObject) {
idEObject.eSet(eReference, convertWrapped(revision, ifcModel, (HashMapWrappedVirtualObject) r));
} else if (r instanceof HashMapVirtualObject) {
} else {
}
}
}
next = queryObjectProvider.next();
}
ifcModel.getModelMetaData().setName(name);
ifcModel.getModelMetaData().setRevisionId(1);
if (getAuthorization().getUoid() != -1) {
ifcModel.getModelMetaData().setAuthorizedUser(getUserByUoid(getAuthorization().getUoid()).getName());
}
ifcModel.getModelMetaData().setDate(new Date());
} catch (IOException e1) {
e1.printStackTrace();
} catch (IfcModelInterfaceException e) {
e.printStackTrace();
} catch (QueryException e) {
e.printStackTrace();
}
}
IfcModelInterface ifcModel = new ServerIfcModel(lastPackageMetaData, pidRoidMap, 0, getDatabaseSession());
if (ifcModelSet.size() > 1) {
setProgress("Merging IFC data...", -1);
try {
ifcModel = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid()).merge(lastProject, ifcModelSet, new ModelHelper(getBimServer().getMetaDataManager(), ifcModel));
} catch (MergeException e) {
throw new UserException(e);
}
} else {
ifcModel = ifcModelSet.iterator().next();
}
ifcModel.getModelMetaData().setName(name);
// ifcModel.getModelMetaData().setRevisionId(project.getRevisions().indexOf(virtualRevision) + 1);
if (getAuthorization().getUoid() != -1) {
ifcModel.getModelMetaData().setAuthorizedUser(getUserByUoid(getAuthorization().getUoid()).getName());
}
ifcModel.getModelMetaData().setDate(new Date());
return ifcModel;
// for (Long roid : roids) {
// Revision virtualRevision = getRevisionByRoid(roid);
// pidRoidMap.put(virtualRevision.getProject().getId(), virtualRevision.getOid());
// project = virtualRevision.getProject();
// name += project.getName() + "-" + virtualRevision.getId() + "-";
// try {
// getAuthorization().canDownload(roid);
// } catch (UserException e) {
// if (!getAuthorization().hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project)) {
// throw new UserException("User has insufficient rights to download revisions from this project");
// }
// if (!getAuthorization().hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project)) {
// throw new UserException("User has insufficient rights to download revisions from this project");
// }
// }
// int size = 0;
//
// for (ConcreteRevision concreteRevision : virtualRevision.getConcreteRevisions()) {
// try {
// int highestStopId = findHighestStopRid(project, concreteRevision);
//
// PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
// lastPackageMetaData = packageMetaData;
// IfcModelInterface subModel = new ServerIfcModel(packageMetaData, pidRoidMap, getDatabaseSession());
//
// OldQuery databaseQuery = new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), virtualRevision.getOid(), null, Deep.NO, highestStopId);
// databaseQuery.updateOidCounters(concreteRevision, getDatabaseSession());
// JsonObject queryObject = (JsonObject)query;
// JsonArray queries = queryObject.get("queries").getAsJsonArray();
// for (JsonElement queryElement : queries) {
// processQueryPart(packageMetaData, queryObject, (JsonObject) queryElement, subModel, databaseQuery);
// }
//
// size += subModel.size();
// subModel.getModelMetaData().setDate(concreteRevision.getDate());
// subModel.fixInverseMismatches();
// checkGeometry(serializerPluginConfiguration, getBimServer().getPluginManager(), subModel, project, concreteRevision, virtualRevision);
// ifcModelSet.add(subModel);
// } catch (GeometryGeneratingException | IfcModelInterfaceException e) {
// throw new UserException(e);
// }
// }
//
// }
// TODO check, double merging??
// IfcModelInterface ifcModel = new BasicIfcModel(lastPackageMetaData, pidRoidMap);
// if (ifcModelSet.size() > 1) {
// try {
// ifcModel = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid()).merge(project, ifcModelSet, new ModelHelper(getBimServer().getMetaDataManager(), ifcModel));
// } catch (MergeException e) {
// throw new UserException(e);
// }
// } else {
// ifcModel = ifcModelSet.iterator().next();
// }
// if (name.endsWith("-")) {
// name = name.substring(0, name.length()-1);
// }
}
Aggregations