use of org.bimserver.shared.interfaces.ServiceInterface in project BIMserver by opensourceBIM.
the class NewExtendedDataOnRevisionNotification method triggerNewExtendedData.
public void triggerNewExtendedData(DatabaseSession session, NotificationsManager notificationsManager, final BimServer bimServer, String siteAddress, Project project, final long roid, Trigger trigger, final Service service) throws UserException, ServerException {
if (service.getTrigger() == trigger) {
Channel channel = null;
try {
channel = notificationsManager.getChannel(service);
final RemoteServiceInterface remoteServiceInterface = channel.get(RemoteServiceInterface.class);
long writeProjectPoid = service.getWriteRevision() == null ? -1 : service.getWriteRevision().getOid();
long writeExtendedDataRoid = service.getWriteExtendedData() != null ? roid : -1;
long readRevisionRoid = service.isReadRevision() ? roid : -1;
long readExtendedDataRoid = service.getReadExtendedData() != null ? roid : -1;
final ExplicitRightsAuthorization authorization = new ExplicitRightsAuthorization(bimServer, service.getUser().getOid(), service.getOid(), new long[] { readRevisionRoid }, writeProjectPoid, readExtendedDataRoid, writeExtendedDataRoid);
ServiceInterface newService = bimServer.getServiceFactory().get(authorization, AccessMethod.INTERNAL).get(ServiceInterface.class);
// TODO redundant?
((org.bimserver.webservices.impl.ServiceImpl) newService).setAuthorization(authorization);
AsyncRemoteServiceInterface asyncRemoteServiceInterface = new AsyncRemoteServiceInterface(remoteServiceInterface, bimServer.getExecutorService());
asyncRemoteServiceInterface.newExtendedDataOnRevision(poid, roid, edid, soid, service.getServiceIdentifier(), service.getProfileIdentifier(), service.getToken(), authorization.asHexToken(bimServer.getEncryptionKey()), bimServer.getServerSettingsCache().getServerSettings().getSiteAddress(), new NewExtendedDataOnRevisionCallback() {
@Override
public void success() {
}
@Override
public void error(Throwable e) {
LOGGER.error("", e);
}
});
asyncRemoteServiceInterface.newRevision(poid, roid, service.getOid(), service.getServiceIdentifier(), service.getProfileIdentifier(), service.getToken(), authorization.asHexToken(bimServer.getEncryptionKey()), bimServer.getServerSettingsCache().getServerSettings().getSiteAddress(), new NewRevisionCallback() {
@Override
public void success() {
}
@Override
public void error(Throwable e) {
LOGGER.error("", e);
}
});
} catch (ChannelConnectionException e) {
LOGGER.error("", e);
} catch (PublicInterfaceNotFoundException e) {
LOGGER.error("", e);
} finally {
if (channel != null) {
// TODO This is interesting, when sending async, is this not going to break?
channel.disconnect();
}
}
}
}
use of org.bimserver.shared.interfaces.ServiceInterface in project BIMserver by opensourceBIM.
the class NewRevisionNotification method triggerNewRevision.
public void triggerNewRevision(DatabaseSession session, NotificationsManager notificationsManager, final BimServer bimServer, String siteAddress, Project project, final long roid, Trigger trigger, final Service service) throws UserException, ServerException {
if (service.getTrigger() == trigger) {
Channel channel = null;
try {
IfcModelInterface model = null;
for (ModelCheckerInstance modelCheckerInstance : service.getModelCheckers()) {
if (modelCheckerInstance.isValid()) {
ModelCheckerPlugin modelCheckerPlugin = bimServer.getPluginManager().getModelCheckerPlugin(modelCheckerInstance.getModelCheckerPluginClassName(), true);
if (modelCheckerPlugin != null) {
ModelChecker modelChecker = modelCheckerPlugin.createModelChecker(null);
ModelCheckerResult result;
try {
if (model == null) {
PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(project.getSchema());
model = new BasicIfcModel(packageMetaData, null);
Revision revision;
try {
revision = session.get(roid, OldQuery.getDefault());
session.getMap(model, new OldQuery(packageMetaData, project.getId(), revision.getId(), revision.getOid(), null, Deep.NO));
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
}
}
result = modelChecker.check(model, modelCheckerInstance.getCompiled());
if (!result.isValid()) {
LOGGER.info("Not triggering");
return;
}
} catch (ModelCheckException e) {
LOGGER.info("Not triggering");
return;
}
}
}
}
channel = notificationsManager.getChannel(service);
final RemoteServiceInterface remoteServiceInterface = channel.get(RemoteServiceInterface.class);
long writeProjectPoid = service.getWriteRevision() == null ? -1 : service.getWriteRevision().getOid();
long writeExtendedDataRoid = service.getWriteExtendedData() != null ? roid : -1;
@SuppressWarnings("unused") long readRevisionRoid = service.isReadRevision() ? roid : -1;
long readExtendedDataRoid = service.getReadExtendedData() != null ? roid : -1;
List<Long> roidsList = new ArrayList<>();
Set<Project> relatedProjects = getRelatedProjects(project);
for (Project p : relatedProjects) {
for (Revision revision : p.getRevisions()) {
roidsList.add(revision.getOid());
}
}
long[] roids = new long[roidsList.size()];
for (int i = 0; i < roids.length; i++) {
roids[i] = roidsList.get(i);
}
final ExplicitRightsAuthorization authorization = new ExplicitRightsAuthorization(bimServer, service.getUser().getOid(), service.getOid(), service.isReadRevision() ? roids : new long[0], writeProjectPoid, readExtendedDataRoid, writeExtendedDataRoid);
ServiceInterface newService = bimServer.getServiceFactory().get(authorization, AccessMethod.INTERNAL).get(ServiceInterface.class);
// TODO redundant?
((org.bimserver.webservices.impl.ServiceImpl) newService).setAuthorization(authorization);
AsyncRemoteServiceInterface asyncRemoteServiceInterface = new AsyncRemoteServiceInterface(remoteServiceInterface, bimServer.getExecutorService());
asyncRemoteServiceInterface.newRevision(poid, roid, service.getOid(), service.getServiceIdentifier(), service.getProfileIdentifier(), service.getToken(), authorization.asHexToken(bimServer.getEncryptionKey()), bimServer.getServerSettingsCache().getServerSettings().getSiteAddress(), new NewRevisionCallback() {
@Override
public void success() {
}
@Override
public void error(Throwable e) {
LOGGER.error("", e);
}
});
} catch (ChannelConnectionException e) {
LOGGER.error("", e);
} catch (PublicInterfaceNotFoundException e) {
LOGGER.error("", e);
} finally {
if (channel != null) {
// TODO This is interesting, when sending async, is this not going to break?
channel.disconnect();
}
}
}
}
use of org.bimserver.shared.interfaces.ServiceInterface in project BIMserver by opensourceBIM.
the class BimServer method initDatabaseDependantItems.
private void initDatabaseDependantItems() throws BimserverDatabaseException {
notificationsManager.init();
getSerializerFactory().init(pluginManager, bimDatabase, this);
try {
DatabaseSession session = bimDatabase.createSession();
try {
updatePlugins(session);
session.commit();
} catch (ServiceException e) {
LOGGER.error("", e);
} finally {
session.close();
}
session = bimDatabase.createSession();
// 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>();
DatabaseSession ses = bimDatabase.createSession();
try {
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));
}
// if (serverSettingsCache.getServerSettings().getWebModule() !=
// null) {
// defaultWebModule = (WebModulePlugin)
// pluginManager.getPlugin(serverSettingsCache.getServerSettings().getWebModule().getPluginDescriptor().getPluginClassName(),
// true);
// }
} finally {
ses.close();
}
Integer protocolBuffersPort = getServerSettingsCache().getServerSettings().getProtocolBuffersPort();
if (protocolBuffersPort >= 1 && protocolBuffersPort <= 65535) {
try {
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()) {
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 {
pluginManager.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);
}
}
Aggregations