use of org.bimserver.models.store.ConcreteRevision in project BIMserver by opensourceBIM.
the class BranchToExistingProjectDatabaseAction method execute.
@Override
public ConcreteRevision execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
Revision oldRevision = getDatabaseSession().get(StorePackage.eINSTANCE.getRevision(), roid, OldQuery.getDefault());
Project oldProject = oldRevision.getProject();
User user = getDatabaseSession().get(StorePackage.eINSTANCE.getUser(), authorization.getUoid(), OldQuery.getDefault());
if (!authorization.hasRightsOnProjectOrSuperProjectsOrSubProjects(user, oldProject)) {
throw new UserException("User has insufficient rights to download revisions from this project");
}
IfcModelSet ifcModelSet = new IfcModelSet();
PackageMetaData lastMetaData = null;
for (ConcreteRevision subRevision : oldRevision.getConcreteRevisions()) {
PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(subRevision.getProject().getSchema());
IfcModel subModel = new BasicIfcModel(packageMetaData, null);
getDatabaseSession().getMap(subModel, new OldQuery(packageMetaData, subRevision.getProject().getId(), subRevision.getId(), -1, Deep.YES));
subModel.getModelMetaData().setDate(subRevision.getDate());
ifcModelSet.add(subModel);
lastMetaData = packageMetaData;
}
IfcModelInterface model = new BasicIfcModel(lastMetaData, null);
try {
model = bimServer.getMergerFactory().createMerger(getDatabaseSession(), authorization.getUoid()).merge(oldRevision.getProject(), ifcModelSet, new ModelHelper(bimServer.getMetaDataManager(), model));
} catch (MergeException e) {
throw new UserException(e);
}
model.resetOids();
CheckinDatabaseAction checkinDatabaseAction = new CheckinDatabaseAction(bimServer, getDatabaseSession(), getAccessMethod(), destPoid, authorization, model, comment, comment, false, -1);
return checkinDatabaseAction.execute();
}
use of org.bimserver.models.store.ConcreteRevision in project BIMserver by opensourceBIM.
the class CheckinDatabaseAction method execute.
@Override
public ConcreteRevision execute() throws UserException, BimserverDatabaseException {
try {
bimServer.getCheckinsInProgress().put(poid, getActingUid());
if (fileSize == -1) {
setProgress("Deserializing IFC file...", -1);
} else {
setProgress("Deserializing IFC file...", 0);
}
if (getModel().size() == 0) {
throw new DeserializeException("Cannot checkin empty model");
}
authorization.canCheckin(poid);
project = getProjectByPoid(poid);
int nrConcreteRevisionsBefore = project.getConcreteRevisions().size();
User user = getUserByUoid(authorization.getUoid());
if (project == null) {
throw new UserException("Project with poid " + poid + " 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");
}
if (getModel() != null) {
checkCheckSum(project, getModel());
}
long size = 0;
if (getModel() != null) {
for (IdEObject idEObject : getModel().getValues()) {
if (idEObject.eClass().getEAnnotation("hidden") == null) {
size++;
}
}
getModel().fixInverseMismatches();
}
for (ModelCheckerInstance modelCheckerInstance : project.getModelCheckers()) {
if (modelCheckerInstance.isValid()) {
ModelCheckerPlugin modelCheckerPlugin = bimServer.getPluginManager().getModelCheckerPlugin(modelCheckerInstance.getModelCheckerPluginClassName(), true);
if (modelCheckerPlugin != null) {
ModelChecker modelChecker = modelCheckerPlugin.createModelChecker(null);
ModelCheckerResult result = modelChecker.check(getModel(), modelCheckerInstance.getCompiled());
if (!result.isValid()) {
throw new UserException("Model is not valid according to " + modelCheckerInstance.getName());
}
}
}
}
CreateRevisionResult result = createNewConcreteRevision(getDatabaseSession(), size, project, user, comment.trim());
concreteRevision = result.getConcreteRevision();
IfcHeader ifcHeader = getModel().getModelMetaData().getIfcHeader();
if (ifcHeader != null) {
getDatabaseSession().store(ifcHeader);
concreteRevision.setIfcHeader(ifcHeader);
}
project.getConcreteRevisions().add(concreteRevision);
if (getModel() != null) {
concreteRevision.setChecksum(getModel().getModelMetaData().getChecksum());
}
final NewRevisionAdded newRevisionAdded = getDatabaseSession().create(NewRevisionAdded.class);
newRevisionAdded.setDate(new Date());
newRevisionAdded.setExecutor(user);
final Revision revision = concreteRevision.getRevisions().get(0);
if (newServiceId != -1) {
NewService newService = getDatabaseSession().get(newServiceId, OldQuery.getDefault());
revision.getServicesLinked().add(newService);
}
concreteRevision.setSummary(new SummaryMap(getModel()).toRevisionSummary(getDatabaseSession()));
// If this revision is being created by an external service, store a link to the service in the revision
if (authorization instanceof ExplicitRightsAuthorization) {
ExplicitRightsAuthorization explicitRightsAuthorization = (ExplicitRightsAuthorization) authorization;
if (explicitRightsAuthorization.getSoid() != -1) {
Service service = getDatabaseSession().get(explicitRightsAuthorization.getSoid(), OldQuery.getDefault());
revision.setService(service);
}
}
newRevisionAdded.setRevision(revision);
newRevisionAdded.setProject(project);
newRevisionAdded.setAccessMethod(getAccessMethod());
Revision lastRevision = project.getLastRevision();
IfcModelInterface ifcModel = null;
if (merge && lastRevision != null) {
ifcModel = checkinMerge(lastRevision);
} else {
ifcModel = getModel();
}
ifcModel.fixOidsFlat(getDatabaseSession());
if (bimServer.getServerSettingsCache().getServerSettings().isGenerateGeometryOnCheckin()) {
setProgress("Generating Geometry...", -1);
UserSettings userSettings = user.getUserSettings();
RenderEnginePluginConfiguration defaultRenderEngine = userSettings.getDefaultRenderEngine();
if (defaultRenderEngine == null) {
throw new UserException("No default render engine has been selected for this user");
}
RenderEnginePool pool = bimServer.getRenderEnginePools().getRenderEnginePool(model.getPackageMetaData().getSchema(), defaultRenderEngine.getPluginDescriptor().getPluginClassName(), new PluginConfiguration(defaultRenderEngine.getSettings()));
GenerateGeometryResult generateGeometry = new GeometryGenerator(bimServer).generateGeometry(pool, bimServer.getPluginManager(), getDatabaseSession(), ifcModel, project.getId(), concreteRevision.getId(), true, geometryCache);
concreteRevision.setMinBounds(generateGeometry.getMinBoundsAsVector3f());
concreteRevision.setMaxBounds(generateGeometry.getMaxBoundsAsVector3f());
for (Revision other : concreteRevision.getRevisions()) {
other.setHasGeometry(true);
}
}
if (nrConcreteRevisionsBefore != 0 && !merge) {
// There already was a revision, lets delete it (only when not merging)
concreteRevision.setClear(true);
}
Set<EClass> eClasses = ifcModel.getUsedClasses();
Map<EClass, Long> startOids = getDatabaseSession().getStartOids();
if (startOids == null) {
throw new BimserverDatabaseException("No objects changed");
}
int s = 0;
for (EClass eClass : eClasses) {
if (!DatabaseSession.perRecordVersioning(eClass)) {
s++;
}
}
ByteBuffer buffer = ByteBuffer.allocate(8 * s);
buffer.order(ByteOrder.LITTLE_ENDIAN);
for (EClass eClass : eClasses) {
long oid = startOids.get(eClass);
if (!DatabaseSession.perRecordVersioning(eClass)) {
buffer.putLong(oid);
}
}
concreteRevision.setOidCounters(buffer.array());
if (ifcModel != null) {
getDatabaseSession().store(ifcModel.getValues(), project.getId(), concreteRevision.getId());
}
getDatabaseSession().addPostCommitAction(new PostCommitAction() {
@Override
public void execute() throws UserException {
bimServer.getCheckinsInProgress().remove(poid);
bimServer.getNotificationsManager().notify(new NewRevisionNotification(bimServer, project.getOid(), revision.getOid(), authorization));
}
});
getDatabaseSession().store(concreteRevision);
getDatabaseSession().store(project);
} catch (Throwable e) {
if (e instanceof BimserverDatabaseException) {
throw (BimserverDatabaseException) e;
}
if (e instanceof UserException) {
throw (UserException) e;
}
LOGGER.error("", e);
throw new UserException(e);
}
return concreteRevision;
}
use of org.bimserver.models.store.ConcreteRevision in project BIMserver by opensourceBIM.
the class DownloadDatabaseAction method execute.
@Override
public IfcModelInterface execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
Revision revision = getRevisionByRoid(roid);
PluginConfiguration serializerPluginConfiguration = getDatabaseSession().get(StorePackage.eINSTANCE.getPluginConfiguration(), serializerOid, OldQuery.getDefault());
getAuthorization().canDownload(roid);
if (revision == null) {
throw new UserException("Revision with oid " + roid + " not found");
}
Project project = revision.getProject();
User user = getUserByUoid(getAuthorization().getUoid());
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");
}
}
IfcModelSet ifcModelSet = new IfcModelSet();
long incrSize = 0;
EList<ConcreteRevision> concreteRevisions = revision.getConcreteRevisions();
if (concreteRevisions.size() == 0) {
throw new ServerException("No concrete revisions in revision");
}
for (ConcreteRevision subRevision : concreteRevisions) {
incrSize += subRevision.getSize();
}
final long totalSize = incrSize;
final AtomicLong total = new AtomicLong();
IfcHeader ifcHeader = null;
PackageMetaData lastPackageMetaData = null;
Map<Integer, Long> pidRoidMap = new HashMap<>();
pidRoidMap.put(project.getId(), roid);
for (ConcreteRevision concreteRevision : concreteRevisions) {
if (concreteRevision.getUser().getOid() != ignoreUoid) {
PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
lastPackageMetaData = packageMetaData;
IfcModel subModel = new ServerIfcModel(packageMetaData, pidRoidMap, getDatabaseSession());
ifcHeader = concreteRevision.getIfcHeader();
int highestStopId = findHighestStopRid(project, concreteRevision);
OldQuery query = new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), concreteRevision.getOid(), objectIDM, Deep.YES, highestStopId);
subModel.addChangeListener(new IfcModelChangeListener() {
@Override
public void objectAdded(IdEObject idEObject) {
total.incrementAndGet();
if (totalSize == 0) {
setProgress("Preparing download...", 0);
} else {
setProgress("Preparing download...", (int) Math.round(100.0 * total.get() / totalSize));
}
}
});
query.updateOidCounters(concreteRevision, getDatabaseSession());
getDatabaseSession().getMap(subModel, query);
if (serializerPluginConfiguration != null) {
try {
checkGeometry(serializerPluginConfiguration, getBimServer().getPluginManager(), subModel, project, concreteRevision, revision);
} catch (GeometryGeneratingException e) {
throw new UserException(e);
}
}
subModel.getModelMetaData().setDate(concreteRevision.getDate());
ifcModelSet.add(subModel);
}
}
IfcModelInterface ifcModel = new ServerIfcModel(lastPackageMetaData, pidRoidMap, getDatabaseSession());
if (ifcModelSet.size() > 1) {
try {
ifcModel = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid()).merge(revision.getProject(), ifcModelSet, new ModelHelper(getBimServer().getMetaDataManager(), ifcModel));
} catch (MergeException e) {
throw new UserException(e);
}
} else {
ifcModel = ifcModelSet.iterator().next();
}
if (ifcHeader != null) {
ifcHeader.load();
ifcModel.getModelMetaData().setIfcHeader(ifcHeader);
}
ifcModel.getModelMetaData().setName(project.getName() + "." + revision.getId());
ifcModel.getModelMetaData().setRevisionId(project.getRevisions().indexOf(revision) + 1);
if (user != null) {
ifcModel.getModelMetaData().setAuthorizedUser(user.getName());
}
ifcModel.getModelMetaData().setDate(revision.getDate());
if (revision.getProject().getGeoTag() != null) {
// ifcModel.setLon(revision.getProject().getGeoTag().getX());
// ifcModel.setLat(revision.getProject().getGeoTag().getY());
// ifcModel.setAltitude((int)
// revision.getProject().getGeoTag().getZ());
// ifcModel.setDirectionAngle(revision.getProject().getGeoTag().getDirectionAngle());
// try {
// CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:" +
// revision.getProject().getGeoTag().getEpsg());
// CoordinateReferenceSystem targetCRS =
// DefaultGeocentricCRS.CARTESIAN;
// MathTransform transform = CRS.findMathTransform(sourceCRS,
// targetCRS, true);
// float[] in = new
// float[]{revision.getProject().getGeoTag().getX1(),
// revision.getProject().getGeoTag().getY1(),
// revision.getProject().getGeoTag().getZ1()};
// float[] result = new float[3];
// transform.transform(in, 0, result, 0, 1);
// IfcModel.setLon(result[0]);
// IfcModel.setLat(result[1]);
// } catch (NoSuchAuthorityCodeException e) {
// LOGGER.error("", e);
// } catch (FactoryException e) {
// LOGGER.error("", e);
// } catch (MismatchedDimensionException e) {
// LOGGER.error("", e);
// } catch (TransformException e) {
// LOGGER.error("", e);
// }
}
return ifcModel;
}
use of org.bimserver.models.store.ConcreteRevision in project BIMserver by opensourceBIM.
the class DownloadProjectsDatabaseAction method execute.
@Override
public IfcModelInterface execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
User user = getUserByUoid(getAuthorization().getUoid());
Project project = null;
String projectName = "";
IfcModelSet ifcModelSet = new IfcModelSet();
long incrSize = 0;
for (long roid : roids) {
Revision revision = getRevisionByRoid(roid);
for (ConcreteRevision subRevision : revision.getConcreteRevisions()) {
incrSize += subRevision.getSize();
}
}
final long totalSize = incrSize;
final AtomicLong total = new AtomicLong();
PluginConfiguration serializerPluginConfiguration = getDatabaseSession().get(StorePackage.eINSTANCE.getPluginConfiguration(), serializerOid, OldQuery.getDefault());
PackageMetaData lastPackageMetaData = null;
IfcHeader ifcHeader = null;
Map<Integer, Long> pidRoidMap = new HashMap<>();
for (long roid : roids) {
Revision revision = getRevisionByRoid(roid);
project = revision.getProject();
pidRoidMap.put(project.getId(), roid);
if (getAuthorization().hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project)) {
for (ConcreteRevision concreteRevision : revision.getConcreteRevisions()) {
ifcHeader = concreteRevision.getIfcHeader();
PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
lastPackageMetaData = packageMetaData;
IfcModel subModel = new ServerIfcModel(packageMetaData, pidRoidMap, getDatabaseSession());
int highestStopId = findHighestStopRid(project, concreteRevision);
OldQuery query = new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), revision.getOid(), objectIDM, Deep.YES, highestStopId);
subModel.addChangeListener(new IfcModelChangeListener() {
@Override
public void objectAdded(IdEObject idEObject) {
total.incrementAndGet();
if (totalSize == 0) {
setProgress("Preparing download...", 0);
} else {
setProgress("Preparing download...", (int) Math.round(100.0 * total.get() / totalSize));
}
}
});
query.updateOidCounters(concreteRevision, getDatabaseSession());
getDatabaseSession().getMap(subModel, query);
projectName += concreteRevision.getProject().getName() + "-";
subModel.getModelMetaData().setDate(concreteRevision.getDate());
try {
checkGeometry(serializerPluginConfiguration, getBimServer().getPluginManager(), subModel, project, concreteRevision, revision);
} catch (GeometryGeneratingException e) {
throw new UserException(e);
}
ifcModelSet.add(subModel);
}
} else {
throw new UserException("User has no rights on project " + project.getOid());
}
}
IfcModelInterface ifcModel = new ServerIfcModel(lastPackageMetaData, pidRoidMap, getDatabaseSession());
if (ifcModelSet.size() == 1) {
ifcModel = ifcModelSet.iterator().next();
} else {
try {
ifcModel = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid()).merge(project, ifcModelSet, new ModelHelper(getBimServer().getMetaDataManager(), ifcModel));
} catch (MergeException e) {
throw new UserException(e);
}
}
if (ifcHeader != null) {
ifcHeader.load();
ifcModel.getModelMetaData().setIfcHeader(ifcHeader);
}
if (projectName.endsWith("-")) {
projectName = projectName.substring(0, projectName.length() - 1);
}
ifcModel.getModelMetaData().setName(projectName);
return ifcModel;
}
use of org.bimserver.models.store.ConcreteRevision in project BIMserver by opensourceBIM.
the class GenericCheckinDatabaseAction method checkCheckSum.
protected void checkCheckSum(Project project, IfcModelInterface model) throws UserException {
ConcreteRevision lastConcreteRevision = project.getLastConcreteRevision();
if (lastConcreteRevision != null) {
int revisionId = -1;
for (Revision revision : lastConcreteRevision.getRevisions()) {
if (revision.getProject() == project) {
revisionId = revision.getId();
}
}
byte[] revisionChecksum = lastConcreteRevision.getChecksum();
if (revisionChecksum != null && model.getModelMetaData().getChecksum() != null) {
if (Arrays.equals(revisionChecksum, model.getModelMetaData().getChecksum())) {
throw new UserException("Uploaded model is the same as last revision (" + revisionId + "), duplicate model not stored");
}
}
}
}
Aggregations