@Override public IfcModelInterface execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException { User user = getUserByUoid(getAuthorization().getUoid()); Set<String> foundNames = new HashSet<String>(); IfcModelSet ifcModelSet = new IfcModelSet(); Project project = null; long incrSize = 0L; SerializerPluginConfiguration serializerPluginConfiguration = getDatabaseSession() .get( StorePackage.eINSTANCE.getSerializerPluginConfiguration(), serializerOid, Query.getDefault()); for (Long roid : roids) { Revision virtualRevision = getRevisionByRoid(roid); project = virtualRevision.getProject(); if (!getAuthorization().hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project)) { throw new UserException( "User has insufficient rights to download revisions from this project"); } Map<ConcreteRevision, Set<Long>> map = new HashMap<ConcreteRevision, Set<Long>>(); for (String name : names) { if (!foundNames.contains(name)) { for (ConcreteRevision concreteRevision : virtualRevision.getConcreteRevisions()) { for (ObjectIdentifier objectIdentifier : getDatabaseSession() .getOidsOfName( name, concreteRevision.getProject().getId(), concreteRevision.getId())) { foundNames.add(name); if (!map.containsKey(concreteRevision)) { map.put(concreteRevision, new HashSet<Long>()); incrSize += concreteRevision.getSize(); } map.get(concreteRevision).add(objectIdentifier.getOid()); } } } } final long totalSize = incrSize; final AtomicLong total = new AtomicLong(); for (ConcreteRevision concreteRevision : map.keySet()) { IfcModel subModel = new IfcModel(); int highestStopId = findHighestStopRid(project, concreteRevision); Query query = new Query( concreteRevision.getProject().getId(), concreteRevision.getId(), objectIDM, deep, highestStopId); subModel.addChangeListener( new IfcModelChangeListener() { @Override public void objectAdded() { total.incrementAndGet(); progress = (int) Math.round(100.0 * total.get() / totalSize); } }); Set<Long> oids = map.get(concreteRevision); getDatabaseSession().getMapWithOids(subModel, oids, query); subModel.getModelMetaData().setDate(concreteRevision.getDate()); try { checkGeometry( serializerPluginConfiguration, bimServer.getPluginManager(), subModel, project, concreteRevision, virtualRevision); } catch (GeometryGeneratingException e) { throw new UserException(e); } ifcModelSet.add(subModel); } } IfcModelInterface ifcModel = new IfcModel(); try { ifcModel = bimServer .getMergerFactory() .createMerger(getDatabaseSession(), getAuthorization().getUoid()) .merge(project, ifcModelSet, new ModelHelper(ifcModel)); ifcModel.getModelMetaData().setName("query"); for (String name : names) { if (!foundNames.contains(name)) { throw new UserException("Name " + name + " not found"); } } ifcModel.getModelMetaData().setRevisionId(1); ifcModel .getModelMetaData() .setAuthorizedUser(getUserByUoid(getAuthorization().getUoid()).getName()); ifcModel.getModelMetaData().setDate(new Date()); return ifcModel; } catch (MergeException e) { throw new UserException(e); } }
private IfcModel realCheckout( Project project, Revision revision, DatabaseSession databaseSession, User user) throws BimserverLockConflictException, BimserverDatabaseException, UserException { SerializerPluginConfiguration serializerPluginConfiguration = getDatabaseSession() .get( StorePackage.eINSTANCE.getSerializerPluginConfiguration(), serializerOid, Query.getDefault()); final long totalSize = revision.getSize(); final AtomicLong total = new AtomicLong(); IfcModelSet ifcModelSet = new IfcModelSet(); for (ConcreteRevision subRevision : revision.getConcreteRevisions()) { IfcModel subModel = new IfcModel(); int highestStopId = findHighestStopRid(project, subRevision); Query query = new Query( subRevision.getProject().getId(), subRevision.getId(), null, Deep.YES, highestStopId); subModel.addChangeListener( new IfcModelChangeListener() { @Override public void objectAdded() { total.incrementAndGet(); if (totalSize == 0) { setProgress("Preparing checkout...", 0); } else { setProgress( "Preparing checkout...", (int) Math.round(100.0 * total.get() / totalSize)); } } }); getDatabaseSession().getMap(subModel, query); try { checkGeometry( serializerPluginConfiguration, getBimServer().getPluginManager(), subModel, project, subRevision, revision); } catch (GeometryGeneratingException e) { throw new UserException(e); } subModel.getModelMetaData().setDate(subRevision.getDate()); ifcModelSet.add(subModel); } IfcModelInterface ifcModel = new IfcModel(); if (ifcModelSet.size() > 1) { try { ifcModel = getBimServer() .getMergerFactory() .createMerger(getDatabaseSession(), getAuthorization().getUoid()) .merge(revision.getProject(), ifcModelSet, new ModelHelper(ifcModel)); } catch (MergeException e) { throw new UserException(e); } } else { ifcModel = ifcModelSet.iterator().next(); } ifcModel.getModelMetaData().setName(project.getName() + "." + revision.getId()); ifcModel.getModelMetaData().setRevisionId(project.getRevisions().indexOf(revision) + 1); ifcModel.getModelMetaData().setAuthorizedUser(user.getName()); ifcModel.getModelMetaData().setDate(new Date()); return (IfcModel) ifcModel; }