Search in sources :

Example 1 with QueryException

use of org.bimserver.database.queries.om.QueryException 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;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) ServerException(org.bimserver.shared.exceptions.ServerException) IdEObject(org.bimserver.emf.IdEObject) HashMap(java.util.HashMap) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) QueryException(org.bimserver.database.queries.om.QueryException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) IdEObject(org.bimserver.emf.IdEObject) List(java.util.List) ArrayList(java.util.ArrayList) UserException(org.bimserver.shared.exceptions.UserException) EReference(org.eclipse.emf.ecore.EReference)

Example 2 with QueryException

use of org.bimserver.database.queries.om.QueryException 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);
// }
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) AbstractEList(org.eclipse.emf.common.util.AbstractEList) JsonQueryObjectModelConverter(org.bimserver.database.queries.om.JsonQueryObjectModelConverter) ServerIfcModel(org.bimserver.ServerIfcModel) Query(org.bimserver.database.queries.om.Query) OldQuery(org.bimserver.database.OldQuery) HashMapWrappedVirtualObject(org.bimserver.shared.HashMapWrappedVirtualObject) HashMap(java.util.HashMap) IfcModelInterface(org.bimserver.emf.IfcModelInterface) ArrayList(java.util.ArrayList) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) EAttribute(org.eclipse.emf.ecore.EAttribute) MergeException(org.bimserver.plugins.modelmerger.MergeException) QueryObjectProvider(org.bimserver.database.queries.QueryObjectProvider) ArrayList(java.util.ArrayList) AbstractEList(org.eclipse.emf.common.util.AbstractEList) List(java.util.List) UserException(org.bimserver.shared.exceptions.UserException) EReference(org.eclipse.emf.ecore.EReference) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ModelHelper(org.bimserver.plugins.ModelHelper) IdEObject(org.bimserver.emf.IdEObject) PackageMetaData(org.bimserver.emf.PackageMetaData) IOException(java.io.IOException) Date(java.util.Date) Project(org.bimserver.models.store.Project) QueryException(org.bimserver.database.queries.om.QueryException) Revision(org.bimserver.models.store.Revision) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) IfcModelSet(org.bimserver.plugins.IfcModelSet) HashMapWrappedVirtualObject(org.bimserver.shared.HashMapWrappedVirtualObject) IdEObject(org.bimserver.emf.IdEObject) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject)

Example 3 with QueryException

use of org.bimserver.database.queries.om.QueryException in project BIMserver by opensourceBIM.

the class GetNrPrimitivesDatabaseAction method execute.

@Override
public Long execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
    Revision revision = getDatabaseSession().get(roid, OldQuery.getDefault());
    PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(revision.getProject().getSchema());
    if (packageMetaData == null) {
        throw new UserException("Schema not fond");
    }
    try {
        Query query = new Query("test", packageMetaData);
        QueryPart queryPart = query.createQueryPart();
        queryPart.addType(packageMetaData.getEClassIncludingDependencies("GeometryInfo"), true);
        QueryObjectProvider queryObjectProvider = new QueryObjectProvider(getDatabaseSession(), bimServer, query, java.util.Collections.singleton(roid), packageMetaData);
        HashMapVirtualObject next = queryObjectProvider.next();
        long totalPrimitives = 0;
        while (next != null) {
            int nrPrimitives = (int) next.get("primitiveCount");
            totalPrimitives += nrPrimitives;
            next = queryObjectProvider.next();
        }
        return totalPrimitives;
    } catch (QueryException e) {
        e.printStackTrace();
    } catch (JsonParseException e) {
        e.printStackTrace();
    } catch (JsonMappingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : OldQuery(org.bimserver.database.OldQuery) Query(org.bimserver.database.queries.om.Query) PackageMetaData(org.bimserver.emf.PackageMetaData) QueryPart(org.bimserver.database.queries.om.QueryPart) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) QueryException(org.bimserver.database.queries.om.QueryException) Revision(org.bimserver.models.store.Revision) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) QueryObjectProvider(org.bimserver.database.queries.QueryObjectProvider) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) UserException(org.bimserver.shared.exceptions.UserException)

Example 4 with QueryException

use of org.bimserver.database.queries.om.QueryException in project BIMserver by opensourceBIM.

the class ClientIfcModel method getAll.

@Override
public <T extends IdEObject> List<T> getAll(EClass eClass) {
    if (!loadedClasses.contains(eClass.getName()) && modelState != ModelState.FULLY_LOADED) {
        LOGGER.info("Loading all " + eClass.getName());
        try {
            modelState = ModelState.LOADING;
            Query query = new Query(getPackageMetaData());
            QueryPart queryPart = query.createQueryPart();
            queryPart.addType(eClass, false);
            if (includeGeometry && getPackageMetaData().getEClass("IfcProduct").isSuperTypeOf(eClass)) {
                Include include = queryPart.createInclude();
                include.addType(eClass, false);
                include.addField("geometry");
            }
            JsonQueryObjectModelConverter converter = new JsonQueryObjectModelConverter(getPackageMetaData());
            long topicId = bimServerClient.getServiceInterface().download(Collections.singleton(roid), converter.toJson(query).toString(), getJsonSerializerOid(), false);
            waitForDonePreparing(topicId);
            processDownload(topicId);
            bimServerClient.getServiceInterface().cleanupLongAction(topicId);
            loadedClasses.add(eClass.getName());
            rebuildIndexPerClass(eClass);
            modelState = ModelState.NONE;
        } catch (Exception e) {
            LOGGER.error("", e);
        }
    }
    List<T> result = super.getAll(eClass);
    try {
        if (modelState != ModelState.FULLY_LOADED) {
            loadGeometry();
        }
    } catch (ServerException e) {
        e.printStackTrace();
    } catch (UserException e) {
        e.printStackTrace();
    } catch (PublicInterfaceNotFoundException e) {
        e.printStackTrace();
    } catch (QueryException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (GeometryException e) {
        e.printStackTrace();
    } catch (IfcModelInterfaceException e) {
        e.printStackTrace();
    }
    return result;
}
Also used : JsonQueryObjectModelConverter(org.bimserver.database.queries.om.JsonQueryObjectModelConverter) ServerException(org.bimserver.shared.exceptions.ServerException) Query(org.bimserver.database.queries.om.Query) QueryPart(org.bimserver.database.queries.om.QueryPart) Include(org.bimserver.database.queries.om.Include) IOException(java.io.IOException) QueryException(org.bimserver.database.queries.om.QueryException) EOFException(java.io.EOFException) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) UserException(org.bimserver.shared.exceptions.UserException) ServiceException(org.bimserver.shared.exceptions.ServiceException) ObjectAlreadyExistsException(org.bimserver.plugins.ObjectAlreadyExistsException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) IOException(java.io.IOException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) ServerException(org.bimserver.shared.exceptions.ServerException) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) QueryException(org.bimserver.database.queries.om.QueryException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) UserException(org.bimserver.shared.exceptions.UserException)

Example 5 with QueryException

use of org.bimserver.database.queries.om.QueryException in project BIMserver by opensourceBIM.

the class CommitTransactionDatabaseAction method execute.

@Override
public ConcreteRevision execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Project project = getProjectByPoid(longTransaction.getPoid());
    User user = getUserByUoid(authorization.getUoid());
    if (project == null) {
        throw new UserException("Project with poid " + longTransaction.getPoid() + " not found");
    }
    if (!authorization.hasRightsOnProjectOrSuperProjects(user, project)) {
        throw new UserException("User has no rights to checkin models to this project");
    }
    if (!MailSystem.isValidEmailAddress(user.getUsername())) {
        throw new UserException("Users must have a valid e-mail address to checkin");
    }
    long size = 0;
    Revision previousRevision = project.getLastRevision();
    if (project.getLastRevision() != null) {
        size += project.getLastRevision().getSize();
    // for (ConcreteRevision concreteRevision : project.getLastRevision().getConcreteRevisions()) {
    // size += concreteRevision.getSize();
    // }
    }
    for (Change change : longTransaction.getChanges()) {
        if (change instanceof CreateObjectChange) {
            size++;
        } else if (change instanceof RemoveObjectChange) {
            size--;
        }
    }
    Revision oldLastRevision = project.getLastRevision();
    CreateRevisionResult result = createNewConcreteRevision(getDatabaseSession(), size, project, user, comment.trim());
    ConcreteRevision concreteRevision = result.getConcreteRevision();
    revision = concreteRevision.getRevisions().get(0);
    project.setLastRevision(revision);
    final NewRevisionAdded newRevisionAdded = getDatabaseSession().create(NewRevisionAdded.class);
    newRevisionAdded.setDate(new Date());
    newRevisionAdded.setExecutor(user);
    newRevisionAdded.setRevision(concreteRevision.getRevisions().get(0));
    newRevisionAdded.setProject(project);
    newRevisionAdded.setAccessMethod(getAccessMethod());
    PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(project.getSchema());
    // IfcModelInterface ifcModel = new BasicIfcModel(packageMetaData, null);
    if (oldLastRevision != null) {
        int highestStopId = AbstractDownloadDatabaseAction.findHighestStopRid(project, oldLastRevision.getLastConcreteRevision());
        OldQuery query = new OldQuery(longTransaction.getPackageMetaData(), project.getId(), oldLastRevision.getId(), -1, null, Deep.YES, highestStopId);
        query.updateOidCounters(oldLastRevision.getLastConcreteRevision(), getDatabaseSession());
    // getDatabaseSession().getMap(ifcModel, query);
    }
    getDatabaseSession().addPostCommitAction(new PostCommitAction() {

        @Override
        public void execute() throws UserException {
            bimServer.getNotificationsManager().notify(new SConverter().convertToSObject(newRevisionAdded));
            try {
                bimServer.getLongTransactionManager().remove(longTransaction.getTid());
            } catch (NoTransactionException e) {
                LOGGER.error("", e);
            }
        }
    });
    SummaryMap summaryMap = null;
    if (oldLastRevision != null && oldLastRevision.getConcreteRevisions().size() == 1 && oldLastRevision.getConcreteRevisions().get(0).getSummary() != null) {
        summaryMap = new SummaryMap(packageMetaData, oldLastRevision.getConcreteRevisions().get(0).getSummary());
    } else {
        summaryMap = new SummaryMap(packageMetaData);
    }
    boolean geometryChanged = true;
    // TODO actually change this variable...
    // First create all new objects
    Transaction transaction = new Transaction(bimServer, previousRevision, project, concreteRevision, getDatabaseSession());
    for (Change change : longTransaction.getChanges()) {
        if (change instanceof CreateObjectChange) {
            try {
                change.execute(transaction);
            } catch (IOException | QueryException e) {
                e.printStackTrace();
            }
            summaryMap.add(((CreateObjectChange) change).geteClass(), 1);
        }
    }
    // Then do the rest
    for (Change change : longTransaction.getChanges()) {
        if (!(change instanceof CreateObjectChange)) {
            if (change instanceof RemoveObjectChange) {
                summaryMap.remove(((RemoveObjectChange) change).geteClass(), 1);
            }
            try {
                change.execute(transaction);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (QueryException e) {
                e.printStackTrace();
            }
        }
    }
    for (HashMapVirtualObject object : transaction.getCreated()) {
        getDatabaseSession().save(object);
    }
    for (HashMapVirtualObject object : transaction.getUpdated()) {
        getDatabaseSession().save(object, concreteRevision.getId());
    }
    for (HashMapVirtualObject object : transaction.getDeleted()) {
        getDatabaseSession().delete(object, concreteRevision.getId());
    }
    if (bimServer.getServerSettingsCache().getServerSettings().isGenerateGeometryOnCheckin() && geometryChanged) {
        setProgress("Generating Geometry...", -1);
        try {
            GeometryGenerationReport report = new GeometryGenerationReport();
            report.setOriginalDeserializer("No deserializer, low level call");
            report.setOriginalIfcFileName("No file, low level call");
            report.setOriginalIfcFileSize(-1);
            StreamingGeometryGenerator streamingGeometryGenerator = new StreamingGeometryGenerator(bimServer, null, -1L, report);
            int highestStopId = AbstractDownloadDatabaseAction.findHighestStopRid(concreteRevision.getProject(), concreteRevision);
            QueryContext queryContext = new QueryContext(getDatabaseSession(), packageMetaData, project.getId(), concreteRevision.getId(), concreteRevision.getRevisions().get(0).getOid(), highestStopId);
            Map<EClass, Long> startOids = getDatabaseSession().getStartOids();
            if (startOids == null) {
                throw new BimserverDatabaseException("No objects changed");
            }
            Map<EClass, Long> oidCounters = new HashMap<>();
            // buffer.order(ByteOrder.LITTLE_ENDIAN);
            for (EClass eClass : packageMetaData.getEClasses()) {
                if (startOids.containsKey(eClass)) {
                    long oid = startOids.get(eClass);
                    if (!DatabaseSession.perRecordVersioning(eClass)) {
                        oidCounters.put(eClass, oid);
                    // buffer.putLong(oid);
                    }
                }
            }
            queryContext.setOidCounters(oidCounters);
            GenerateGeometryResult generateGeometry = streamingGeometryGenerator.generateGeometry(authorization.getUoid(), getDatabaseSession(), queryContext);
            concreteRevision.setMinBounds(generateGeometry.getMinBoundsAsVector3f());
            concreteRevision.setMaxBounds(generateGeometry.getMaxBoundsAsVector3f());
        } catch (GeometryGeneratingException e) {
            throw new UserException(e);
        }
        revision.setHasGeometry(true);
    }
    if (oldLastRevision != null) {
        concreteRevision.setOidCounters(oldLastRevision.getConcreteRevisions().get(0).getOidCounters());
    }
    concreteRevision.setSummary(summaryMap.toRevisionSummary(getDatabaseSession()));
    getDatabaseSession().store(concreteRevision);
    getDatabaseSession().store(project);
    return concreteRevision;
}
Also used : User(org.bimserver.models.store.User) HashMap(java.util.HashMap) RemoveObjectChange(org.bimserver.changes.RemoveObjectChange) GeometryGeneratingException(org.bimserver.GeometryGeneratingException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) GeometryGenerationReport(org.bimserver.geometry.GeometryGenerationReport) EClass(org.eclipse.emf.ecore.EClass) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) CreateObjectChange(org.bimserver.changes.CreateObjectChange) UserException(org.bimserver.shared.exceptions.UserException) NewRevisionAdded(org.bimserver.models.log.NewRevisionAdded) NoTransactionException(org.bimserver.webservices.NoTransactionException) SConverter(org.bimserver.interfaces.SConverter) PackageMetaData(org.bimserver.emf.PackageMetaData) PostCommitAction(org.bimserver.database.PostCommitAction) StreamingGeometryGenerator(org.bimserver.geometry.StreamingGeometryGenerator) RemoveObjectChange(org.bimserver.changes.RemoveObjectChange) CreateObjectChange(org.bimserver.changes.CreateObjectChange) Change(org.bimserver.changes.Change) IOException(java.io.IOException) QueryContext(org.bimserver.shared.QueryContext) Date(java.util.Date) OldQuery(org.bimserver.database.OldQuery) Project(org.bimserver.models.store.Project) QueryException(org.bimserver.database.queries.om.QueryException) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) SummaryMap(org.bimserver.SummaryMap) LongTransaction(org.bimserver.webservices.LongTransaction) Transaction(org.bimserver.changes.Transaction) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) GenerateGeometryResult(org.bimserver.GenerateGeometryResult)

Aggregations

QueryException (org.bimserver.database.queries.om.QueryException)7 IOException (java.io.IOException)5 Query (org.bimserver.database.queries.om.Query)5 UserException (org.bimserver.shared.exceptions.UserException)5 JsonQueryObjectModelConverter (org.bimserver.database.queries.om.JsonQueryObjectModelConverter)4 IfcModelInterfaceException (org.bimserver.emf.IfcModelInterfaceException)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 HashMap (java.util.HashMap)3 OldQuery (org.bimserver.database.OldQuery)3 QueryPart (org.bimserver.database.queries.om.QueryPart)3 PackageMetaData (org.bimserver.emf.PackageMetaData)3 Revision (org.bimserver.models.store.Revision)3 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 List (java.util.List)2 QueryObjectProvider (org.bimserver.database.queries.QueryObjectProvider)2 IdEObject (org.bimserver.emf.IdEObject)2 IdEObjectImpl (org.bimserver.emf.IdEObjectImpl)2 Project (org.bimserver.models.store.Project)2