use of org.bimserver.BimserverDatabaseException 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;
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class DownloadQueryDatabaseAction method execute.
@Override
public IfcModelInterface execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
DatabaseSession session = getBimServer().getDatabase().createSession();
try {
SerializerPluginConfiguration serializerPluginConfiguration = getDatabaseSession().get(StorePackage.eINSTANCE.getSerializerPluginConfiguration(), serializerOid, OldQuery.getDefault());
BimDatabaseAction<IfcModelInterface> action = new DownloadDatabaseAction(getBimServer(), session, AccessMethod.INTERNAL, roid, -1, serializerPluginConfiguration.getOid(), getAuthorization(), null);
IfcModelInterface ifcModel = session.executeAndCommitAction(action);
QueryEnginePluginConfiguration queryEngineObject = session.get(StorePackage.eINSTANCE.getQueryEnginePluginConfiguration(), qeid, OldQuery.getDefault());
Revision revision = session.get(roid, OldQuery.getDefault());
PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(revision.getProject().getSchema());
if (objectIDM == null) {
objectIDM = new HideAllInversesObjectIDM(CollectionUtils.singleSet(Ifc2x3tc1Package.eINSTANCE), packageMetaData);
}
if (queryEngineObject != null) {
QueryEnginePlugin queryEnginePlugin = getBimServer().getPluginManager().getQueryEngine(queryEngineObject.getPluginDescriptor().getPluginClassName(), true);
if (queryEnginePlugin != null) {
QueryEngine queryEngine = queryEnginePlugin.getQueryEngine(new PluginConfiguration(queryEngineObject.getSettings()));
final IfcModelInterface result = new ServerIfcModel(packageMetaData, null, getDatabaseSession());
ModelHelper modelHelper = new ModelHelper(getBimServer().getMetaDataManager(), objectIDM, result);
modelHelper.setOidProvider(new OidProvider() {
private long oid = 1000000;
@Override
public long newOid(EClass eClass) {
return oid++;
}
});
IfcModelInterface finalResult = queryEngine.query(ifcModel, code, new Reporter() {
@Override
public void error(Throwable error) {
}
@Override
public void warning(String warning) {
}
@Override
public void info(String info) {
}
}, modelHelper);
return finalResult;
} else {
throw new UserException("No Query Engine found " + queryEngineObject.getPluginDescriptor().getPluginClassName());
}
} else {
throw new UserException("No configured query engine found with qeid " + qeid);
}
} catch (BimserverDatabaseException e) {
throw new UserException(e);
} catch (QueryEngineException e) {
throw new UserException(e);
} catch (PluginException e) {
throw new UserException(e);
} finally {
session.close();
}
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class InstallPluginBundle method execute.
@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
LOGGER.info("Installing plugin " + repository + " " + groupId + "." + artifactId + "." + version);
MavenPluginLocation mavenPluginLocation = bimServer.getMavenPluginRepository().getPluginLocation(repository, groupId, artifactId);
if (version == null) {
String latestVersion = mavenPluginLocation.getLatestVersionString();
LOGGER.info("Using version " + latestVersion + " because no version given");
version = latestVersion;
}
try {
LOGGER.info(mavenPluginLocation.getRepository(version));
} catch (Exception e1) {
e1.printStackTrace();
}
MavenPluginBundle mavenPluginBundle = mavenPluginLocation.getMavenPluginBundle(version);
LOGGER.info(mavenPluginBundle.getVersion());
try {
bimServer.getPluginManager().install(mavenPluginBundle, plugins, false);
} catch (Exception e) {
LOGGER.error("", e);
throw new UserException(e);
}
return null;
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class InstallPluginBundleFromBytes method execute.
@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
LocalMavenPluginBundle mavenPluginBundle = new LocalMavenPluginBundle(data);
try {
List<SPluginInformation> pluginInformationFromPluginFile = bimServer.getPluginManager().getPluginInformationFromJar(new ByteArrayInputStream(data));
for (SPluginInformation sPluginInformation : pluginInformationFromPluginFile) {
sPluginInformation.setEnabled(true);
if (installAllPluginsForAllUsers) {
sPluginInformation.setInstallForAllUsers(true);
}
if (installAllPluginsForNewUsers) {
sPluginInformation.setInstallForNewUsers(true);
}
}
bimServer.getPluginManager().install(mavenPluginBundle, pluginInformationFromPluginFile, false);
} catch (Exception e) {
LOGGER.error("", e);
throw new UserException(e);
}
return null;
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class StreamingCheckinDatabaseAction method rollback.
public void rollback() throws BimserverDatabaseException {
// TODO do we need to remove indices too?
LOGGER.info("Rolling back");
int pid = newRevision.getProject().getId();
int rid = newRevision.getRid();
Map<EClass, Long> startOids = getDatabaseSession().getStartOids();
if (startOids == null) {
throw new BimserverDatabaseException("No objects changed");
}
int deleted = 0;
for (EClass eClass : startOids.keySet()) {
Long startOid = startOids.get(eClass);
ByteBuffer mustStartWith = ByteBuffer.wrap(new byte[4]);
mustStartWith.putInt(pid);
ByteBuffer startSearchWith = ByteBuffer.wrap(new byte[12]);
startSearchWith.putInt(pid);
startSearchWith.putLong(startOid);
String tableName = eClass.getEPackage().getName() + "_" + eClass.getName();
try {
if (!getDatabaseSession().getKeyValueStore().isTransactional(getDatabaseSession(), tableName)) {
// System.out.println("Checking " + tableName);
try (RecordIterator recordIterator = getDatabaseSession().getKeyValueStore().getRecordIterator(tableName, mustStartWith.array(), startSearchWith.array(), getDatabaseSession())) {
Record record = recordIterator.next();
while (record != null) {
// System.out.println("Deleting from " + tableName);
ByteBuffer keyBuffer = ByteBuffer.wrap(record.getKey());
// pid
keyBuffer.getInt();
// oid
keyBuffer.getLong();
int keyRid = -keyBuffer.getInt();
if (keyRid == rid) {
getDatabaseSession().getKeyValueStore().delete(tableName, record.getKey(), getDatabaseSession());
deleted++;
}
record = recordIterator.next();
}
} catch (BimserverLockConflictException e) {
e.printStackTrace();
} catch (BimserverDatabaseException e) {
e.printStackTrace();
}
}
} catch (BimserverDatabaseException e1) {
e1.printStackTrace();
}
}
LOGGER.info("Deleted " + deleted + " objects in rollback");
// getDatabaseSession().getKeyValueStore().sync();
}
Aggregations