use of org.bimserver.emf.IdEObjectImpl in project BIMserver by opensourceBIM.
the class WaitingList method updateNode.
@SuppressWarnings("unchecked")
public void updateNode(T expressId, EClass ec, IdEObject eObject) throws DeserializeException {
for (WaitingObject waitingObject : waitingObjects.get(expressId)) {
if (waitingObject.getEReference().isMany()) {
AbstractEList<EObject> list = (AbstractEList<EObject>) waitingObject.getObject().eGet(waitingObject.getEReference());
if (waitingObject instanceof SingleWaitingObject) {
list.addUnique(eObject);
} else {
ListWaitingObject listWaitingObject = (ListWaitingObject) waitingObject;
if (((EClass) waitingObject.getEReference().getEType()).isSuperTypeOf(eObject.eClass())) {
while (list.size() <= listWaitingObject.getIndex()) {
EObject create = ec.getEPackage().getEFactoryInstance().create(eObject.eClass());
((IdEObjectImpl) create).setOid(-2);
list.addUnique(create);
}
list.setUnique(listWaitingObject.getIndex(), eObject);
} else {
throw new DeserializeException(waitingObject.getLineNumber(), "Field " + waitingObject.getEReference().getName() + " of " + waitingObject.getEReference().getEContainingClass().getName() + " cannot contain a " + eObject.eClass().getName());
}
}
} else {
if (((EClass) waitingObject.getEReference().getEType()).isSuperTypeOf(eObject.eClass())) {
waitingObject.getObject().eSet(waitingObject.getEReference(), eObject);
} else {
throw new DeserializeException(waitingObject.getLineNumber(), "Field " + waitingObject.getEReference().getName() + " of " + waitingObject.getEReference().getEContainingClass().getName() + " cannot contain a " + eObject.eClass().getName() + "/" + eObject.getOid());
}
}
}
waitingObjects.remove(expressId);
}
use of org.bimserver.emf.IdEObjectImpl 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.bimserver.emf.IdEObjectImpl in project BIMserver by opensourceBIM.
the class ClientIfcModel method create.
@SuppressWarnings("unchecked")
@Override
public <T extends IdEObject> T create(EClass eClass) throws IfcModelInterfaceException, ObjectAlreadyExistsException {
final IdEObjectImpl idEObject = (IdEObjectImpl) eClass.getEPackage().getEFactoryInstance().create(eClass);
idEObject.setModel(this);
if (recordChanges) {
idEObject.eAdapters().add(adapter);
try {
Long oid = bimServerClient.getLowLevelInterface().createObject(tid, eClass.getName(), eClass.getEStructuralFeature("GlobalId") != null);
idEObject.setOid(oid);
} catch (Exception e) {
LOGGER.error("", e);
}
add(idEObject.getOid(), idEObject);
}
return (T) idEObject;
}
use of org.bimserver.emf.IdEObjectImpl 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);
// }
}
use of org.bimserver.emf.IdEObjectImpl 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;
}
Aggregations