use of org.bimserver.models.store.ExtendedDataSchema in project BIMserver by opensourceBIM.
the class ServiceImpl method addExtendedDataSchema.
@Override
public Long addExtendedDataSchema(SExtendedDataSchema extendedDataSchema) throws ServerException, UserException {
// requireAdminAuthenticationAndRunningServer();
DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE);
try {
ExtendedDataSchema create = session.create(ExtendedDataSchema.class);
ExtendedDataSchema convert = getBimServer().getSConverter().convertFromSObject(extendedDataSchema, create, session);
return session.executeAndCommitAction(new AddExtendedDataSchemaDatabaseAction(session, getInternalAccessMethod(), convert));
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
use of org.bimserver.models.store.ExtendedDataSchema in project BIMserver by opensourceBIM.
the class BimServer method initDatabaseDependantItems.
private void initDatabaseDependantItems() throws BimserverDatabaseException {
LOGGER.info("Initializing database dependant logic...");
long start = System.nanoTime();
notificationsManager.init();
getSerializerFactory().init(pluginManager, bimDatabase, this);
try {
DatabaseSession session = bimDatabase.createSession(OperationType.POSSIBLY_WRITE);
try {
updatePlugins(session);
session.commit();
} catch (ServiceException e) {
LOGGER.error("", e);
} finally {
session.close();
}
int renderEngineProcesses = getServerSettingsCache().getServerSettings().getRenderEngineProcesses();
RenderEnginePoolFactory renderEnginePoolFactory = new CommonsPoolingRenderEnginePoolFactory(renderEngineProcesses);
renderEnginePools = new RenderEnginePools(this, renderEnginePoolFactory);
session = bimDatabase.createSession(OperationType.POSSIBLY_WRITE);
// createDatabaseObjects(session);
ServerSettings serverSettings = serverSettingsCache.getServerSettings();
for (Entry<PluginContext, WebModulePlugin> entry : pluginManager.getAllWebPlugins(true).entrySet()) {
WebModulePluginConfiguration webPluginConfiguration = find(serverSettings.getWebModules(), entry.getKey().getIdentifier());
if (webPluginConfiguration == null) {
webPluginConfiguration = session.create(WebModulePluginConfiguration.class);
serverSettings.getWebModules().add(webPluginConfiguration);
PluginDescriptor pluginDescriptor = getPluginDescriptor(session, entry.getKey().getIdentifier());
if (pluginDescriptor == null) {
throw new BimserverDatabaseException("No plugin descriptor found: " + entry.getKey().getIdentifier());
}
genericPluginConversion(entry.getKey(), session, webPluginConfiguration, pluginDescriptor);
} else {
if (webPluginConfiguration == serverSettings.getWebModule()) {
setDefaultWebModule(entry.getValue());
}
}
}
// Set the default
// if (serverSettings.getWebModule() == null) {
// WebModulePluginConfiguration bimviewsWebModule = findWebModule(serverSettings, "BIM Views");
// if (bimviewsWebModule != null) {
// serverSettings.setWebModule(bimviewsWebModule);
// setDefaultWebModule(pluginManager.getWebModulePlugin(bimviewsWebModule.getPluginDescriptor().getPluginClassName(), true));
// } else {
// WebModulePluginConfiguration defaultWebModule = findWebModule(serverSettings, "org.bimserver.defaultwebmodule.DefaultWebModulePlugin");
// if (defaultWebModule != null) {
// serverSettings.setWebModule(defaultWebModule);
// setDefaultWebModule(pluginManager.getWebModulePlugin(defaultWebModule.getPluginDescriptor().getPluginClassName(), true));
// }
// }
// }
session.store(serverSettings);
Condition condition = new AttributeCondition(StorePackage.eINSTANCE.getUser_Username(), new StringLiteral("system"));
User systemUser = session.querySingle(condition, User.class, OldQuery.getDefault());
ServerStarted serverStarted = session.create(ServerStarted.class);
serverStarted.setDate(new Date());
serverStarted.setAccessMethod(AccessMethod.INTERNAL);
serverStarted.setExecutor(systemUser);
try {
session.store(serverStarted);
session.commit();
} catch (BimserverLockConflictException e) {
throw new BimserverDatabaseException(e);
} catch (ServiceException e) {
throw new BimserverDatabaseException(e);
} finally {
session.close();
}
webModules = new HashMap<String, WebModulePlugin>();
List<WebModulePluginConfiguration> webModuleConfigurations = serverSettingsCache.getServerSettings().getWebModules();
for (WebModulePluginConfiguration webModulePluginConfiguration : webModuleConfigurations) {
String contextPath = "";
for (Parameter parameter : webModulePluginConfiguration.getSettings().getParameters()) {
if (parameter.getName().equals("contextPath")) {
contextPath = ((StringType) parameter.getValue()).getValue();
}
}
String identifier = webModulePluginConfiguration.getPluginDescriptor().getIdentifier();
webModules.put(contextPath, (WebModulePlugin) pluginManager.getPlugin(identifier, true));
}
try (DatabaseSession databaseSession = getDatabase().createSession(OperationType.POSSIBLY_WRITE)) {
ExtendedDataSchema htmlSchema = (ExtendedDataSchema) databaseSession.querySingle(StorePackage.eINSTANCE.getExtendedDataSchema_Name(), "GEOMETRY_GENERATION_REPORT_HTML_1_1");
ExtendedDataSchema jsonSchema = (ExtendedDataSchema) databaseSession.querySingle(StorePackage.eINSTANCE.getExtendedDataSchema_Name(), "GEOMETRY_GENERATION_REPORT_JSON_1_1");
if (htmlSchema == null) {
htmlSchema = createExtendedDataSchema(databaseSession, "GEOMETRY_GENERATION_REPORT_HTML_1_1", "text/html");
}
if (jsonSchema == null) {
jsonSchema = createExtendedDataSchema(databaseSession, "GEOMETRY_GENERATION_REPORT_JSON_1_1", "application/json");
}
databaseSession.commit();
} catch (ServiceException e) {
LOGGER.error("", e);
}
Integer protocolBuffersPort = getServerSettingsCache().getServerSettings().getProtocolBuffersPort();
if (protocolBuffersPort >= 1 && protocolBuffersPort <= 65535) {
try {
protocolBuffersMetaData = new ProtocolBuffersMetaData();
protocolBuffersMetaData.load(servicesMap, ProtocolBuffersBimServerClientFactory.class);
protocolBuffersServer = new ProtocolBuffersServer(protocolBuffersMetaData, serviceFactory, servicesMap, protocolBuffersPort);
protocolBuffersServer.start();
} catch (Exception e) {
LOGGER.error("", e);
}
}
bimServerClientFactory = new DirectBimServerClientFactory<ServiceInterface>(serverSettingsCache.getServerSettings().getSiteAddress(), serviceFactory, servicesMap, pluginManager, metaDataManager);
pluginManager.setBimServerClientFactory(bimServerClientFactory);
try (DatabaseSession session2 = bimDatabase.createSession(OperationType.READ_ONLY)) {
IfcModelInterface pluginBundleVersions = session2.getAllOfType(StorePackage.eINSTANCE.getPluginBundleVersion(), OldQuery.getDefault());
for (PluginBundleVersion pluginBundleVersion : pluginBundleVersions.getAll(PluginBundleVersion.class)) {
if (pluginBundleVersion.getType() == PluginBundleType.MAVEN || pluginBundleVersion.getType() == PluginBundleType.LOCAL) {
PluginBundleVersionIdentifier pluginBundleVersionIdentifier = new PluginBundleVersionIdentifier(pluginBundleVersion.getGroupId(), pluginBundleVersion.getArtifactId(), pluginBundleVersion.getVersion());
IfcModelInterface pluginDescriptors = session2.getAllOfType(StorePackage.eINSTANCE.getPluginDescriptor(), OldQuery.getDefault());
List<SPluginInformation> plugins = new ArrayList<>();
for (PluginDescriptor pluginDescriptor : pluginDescriptors.getAll(PluginDescriptor.class)) {
if (pluginDescriptor.getPluginBundleVersion() == pluginBundleVersion && pluginDescriptor.getEnabled()) {
SPluginInformation sPluginInformation = new SPluginInformation();
sPluginInformation.setEnabled(true);
sPluginInformation.setDescription(pluginDescriptor.getDescription());
sPluginInformation.setIdentifier(pluginDescriptor.getIdentifier());
sPluginInformation.setInstallForAllUsers(pluginDescriptor.isInstallForNewUsers());
sPluginInformation.setInstallForNewUsers(pluginDescriptor.isInstallForNewUsers());
sPluginInformation.setName(pluginDescriptor.getName());
sPluginInformation.setType(pluginManager.getPluginTypeFromClass(pluginDescriptor.getPluginClassName()));
plugins.add(sPluginInformation);
}
}
try {
pluginBundleManager.loadFromPluginDir(pluginBundleVersionIdentifier, getSConverter().convertToSObject(pluginBundleVersion), plugins, serverSettingsCache.getServerSettings().isPluginStrictVersionChecking());
} catch (Exception e) {
LOGGER.error("", e);
}
}
}
} catch (Exception e) {
throw new BimserverDatabaseException(e);
}
} catch (BimserverLockConflictException e) {
throw new BimserverDatabaseException(e);
// } catch (PluginException e) {
// throw new BimserverDatabaseException(e);
} catch (RenderEngineException e) {
throw new BimserverDatabaseException(e);
}
long end = System.nanoTime();
LOGGER.info("Done initializing database dependant logic (" + ((end - start) / 1000000) + "ms)");
}
use of org.bimserver.models.store.ExtendedDataSchema in project BIMserver by opensourceBIM.
the class BimServer method createExtendedDataSchema.
private ExtendedDataSchema createExtendedDataSchema(DatabaseSession databaseSession, String name, String contentType) throws BimserverDatabaseException {
ExtendedDataSchema extendedDataSchema = databaseSession.create(ExtendedDataSchema.class);
extendedDataSchema.setName(name);
extendedDataSchema.setContentType(contentType);
return extendedDataSchema;
}
use of org.bimserver.models.store.ExtendedDataSchema 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();
ConcreteRevision previousConcreteRevision = null;
if (previousRevision != null) {
previousConcreteRevision = previousRevision.getConcreteRevisions().get(0);
}
if (project.getLastRevision() != null) {
size += project.getLastRevision().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();
if (previousConcreteRevision != null) {
concreteRevision.setIfcHeader(previousConcreteRevision.getIfcHeader());
}
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());
OidCounters originalOidCounters = null;
PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(project.getSchema());
if (oldLastRevision != null) {
int highestStopId = AbstractDownloadDatabaseAction.findHighestStopRid(project, oldLastRevision.getLastConcreteRevision());
OldQuery query = new OldQuery(longTransaction.getPackageMetaData(), project.getId(), oldLastRevision.getId(), -1, Deep.YES, highestStopId);
originalOidCounters = query.updateOidCounters(oldLastRevision.getLastConcreteRevision(), getDatabaseSession());
} else {
originalOidCounters = new OidCounters();
}
getDatabaseSession().addPostCommitAction(new PostCommitAction() {
@Override
public void execute() throws UserException {
getBimServer().getNotificationsManager().notify(new SConverter().convertToSObject(newRevisionAdded));
try {
getBimServer().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);
}
// First create all new objects
Transaction transaction = new Transaction(getBimServer(), previousRevision, project, concreteRevision, getDatabaseSession());
for (Change change : longTransaction.getChanges()) {
if (change instanceof CreateObjectChange) {
try {
CreateObjectChange createObjectChange = (CreateObjectChange) change;
change.execute(transaction);
getDatabaseSession().addStartOid(createObjectChange.geteClass(), createObjectChange.getOid());
} 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());
}
setProgress("Generating inverses/opposites...", -1);
Revision newRevision = result.getRevisions().get(0);
long newRoid = newRevision.getOid();
try {
fixInverses(packageMetaData, newRoid, summaryMap.getSummaryMap());
} catch (QueryException | IOException e1) {
e1.printStackTrace();
}
int highestStopId = AbstractDownloadDatabaseAction.findHighestStopRid(concreteRevision.getProject(), concreteRevision);
QueryContext queryContext = new QueryContext(getDatabaseSession(), packageMetaData, project.getId(), concreteRevision.getId(), concreteRevision.getRevisions().get(0).getOid(), concreteRevision.getOid(), highestStopId);
Map<String, Long> startOids = getDatabaseSession().getStartOids();
if (startOids == null) {
throw new BimserverDatabaseException("No objects changed");
}
for (EClass eClass : packageMetaData.getEClasses()) {
if (startOids.containsKey(eClass.getEPackage().getName() + "." + eClass.getName())) {
long oid = startOids.get(eClass.getEPackage().getName() + "." + eClass.getName());
if (!DatabaseSession.perRecordVersioning(eClass)) {
originalOidCounters.putIfAbsent(eClass, oid);
}
}
}
queryContext.setOidCounters(originalOidCounters);
concreteRevision.setOidCounters(originalOidCounters == null ? null : originalOidCounters.getBytes());
if (getBimServer().getServerSettingsCache().getServerSettings().isGenerateGeometryOnCheckin()) {
if (regenerateAllGeometry) {
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(getBimServer(), null, -1L, report);
GenerateGeometryResult generateGeometry = streamingGeometryGenerator.generateGeometry(authorization.getUoid(), getDatabaseSession(), queryContext, summaryMap.count());
concreteRevision.setMultiplierToMm(generateGeometry.getMultiplierToMm());
concreteRevision.setBounds(generateGeometry.getBounds());
concreteRevision.setBoundsUntransformed(generateGeometry.getBoundsUntransformed());
generateDensityAndBounds(result, generateGeometry, concreteRevision);
final GeometryGenerationReport finalReport = report;
getDatabaseSession().addPostCommitAction(new PostCommitAction() {
@Override
public void execute() throws UserException {
if (finalReport != null) {
byte[] htmlBytes = finalReport.toHtml().getBytes(Charsets.UTF_8);
byte[] jsonBytes = finalReport.toJson().toString().getBytes(Charsets.UTF_8);
try (DatabaseSession tmpSession = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE)) {
AddGeometryReports addGeometryReports = new AddGeometryReports(tmpSession, AccessMethod.INTERNAL, htmlBytes, jsonBytes, finalReport.getTimeToGenerateMs(), authorization.getUoid(), revision.getOid());
try {
tmpSession.executeAndCommitAction(addGeometryReports);
} catch (ServerException e1) {
LOGGER.error("", e1);
}
} catch (BimserverDatabaseException e1) {
LOGGER.error("", e1);
}
}
getBimServer().getNotificationsManager().notify(new NewRevisionNotification(getBimServer(), project.getOid(), revision.getOid(), authorization));
}
});
} catch (GeometryGeneratingException e) {
throw new UserException(e);
}
revision.setHasGeometry(true);
} else {
if (previousRevision != null) {
byte[] htmlBytes = null;
byte[] jsonBytes = null;
long timeToGenerate = -1;
for (ExtendedData previousExtendedData : previousRevision.getExtendedData()) {
ExtendedDataSchema previousSchema = previousExtendedData.getSchema();
if (previousSchema.getName().contentEquals("GEOMETRY_GENERATION_REPORT_HTML_1_1")) {
htmlBytes = previousExtendedData.getFile().getData();
} else if (previousSchema.getName().contentEquals("GEOMETRY_GENERATION_REPORT_JSON_1_1")) {
jsonBytes = previousExtendedData.getFile().getData();
}
}
byte[] finalHtmlBytes = htmlBytes;
byte[] finalJsonBytes = jsonBytes;
getDatabaseSession().addPostCommitAction(new PostCommitAction() {
public void execute() throws UserException {
try (DatabaseSession tmpSession = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE)) {
AddGeometryReports addGeometryReports = new AddGeometryReports(tmpSession, AccessMethod.INTERNAL, finalHtmlBytes, finalJsonBytes, timeToGenerate, authorization.getUoid(), revision.getOid());
try {
tmpSession.executeAndCommitAction(addGeometryReports);
} catch (ServerException e1) {
LOGGER.error("", e1);
}
} catch (BimserverDatabaseException e1) {
LOGGER.error("", e1);
}
}
});
concreteRevision.setMultiplierToMm(previousConcreteRevision.getMultiplierToMm());
concreteRevision.setBounds(previousConcreteRevision.getBounds());
concreteRevision.setBoundsUntransformed(previousConcreteRevision.getBoundsUntransformed());
newRevision.setBounds(previousRevision.getBounds());
newRevision.setBoundsUntransformed(previousRevision.getBoundsUntransformed());
newRevision.setBoundsMm(previousRevision.getBoundsMm());
newRevision.setBoundsUntransformedMm(previousRevision.getBoundsUntransformedMm());
// TODO validate this, contains ids?
newRevision.setDensityCollection(previousRevision.getDensityCollection());
revision.setHasGeometry(true);
}
}
}
concreteRevision.setSummary(summaryMap.toRevisionSummary(getDatabaseSession()));
getDatabaseSession().store(concreteRevision);
getDatabaseSession().store(project);
return concreteRevision;
}
use of org.bimserver.models.store.ExtendedDataSchema in project BIMserver by opensourceBIM.
the class AddUserToExtendedDataSchemaDatabaseAction method execute.
@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
User user = getDatabaseSession().get(StorePackage.eINSTANCE.getUser(), uoid, OldQuery.getDefault());
if (user == null) {
throw new UserException("User with oid " + uoid + " not found");
}
ExtendedDataSchema extendedDataSchema = getDatabaseSession().get(StorePackage.eINSTANCE.getExtendedDataSchema(), edsid, OldQuery.getDefault());
if (extendedDataSchema == null) {
throw new UserException("ExtendedDataSchema with oid " + edsid + " not found");
}
user.getSchemas().add(extendedDataSchema);
getDatabaseSession().store(user);
getDatabaseSession().store(extendedDataSchema);
return null;
}
Aggregations