use of org.bimserver.interfaces.objects.SObjectType in project BIMserver by opensourceBIM.
the class AbstractService method register.
@Override
public void register(long uoid, SInternalServicePluginConfiguration internalService, final PluginConfiguration pluginConfiguration) {
name = internalService.getName();
ServiceDescriptor serviceDescriptor = StoreFactory.eINSTANCE.createServiceDescriptor();
serviceDescriptor.setProviderName("BIMserver");
serviceDescriptor.setIdentifier("" + internalService.getOid());
serviceDescriptor.setName(internalService.getName());
serviceDescriptor.setDescription(internalService.getDescription());
serviceDescriptor.setNotificationProtocol(AccessMethod.INTERNAL);
serviceDescriptor.setTrigger(Trigger.NEW_REVISION);
addRequiredRights(serviceDescriptor);
serviceDescriptor.setReadRevision(true);
registerNewRevisionHandler(uoid, serviceDescriptor, new NewRevisionHandler() {
@Override
public void newRevision(BimServerClientInterface bimServerClientInterface, long poid, long roid, String userToken, long soid, SObjectType settings) throws ServerException, UserException {
try {
Long topicId = bimServerClientInterface.getRegistry().registerProgressOnRevisionTopic(SProgressTopicType.RUNNING_SERVICE, poid, roid, "Running " + name);
RunningService runningService = new RunningService(topicId, bimServerClientInterface, pluginConfiguration, bimServerClientInterface.getAuthInterface().getLoggedInUser().getUsername());
try {
SLongActionState state = new SLongActionState();
state.setProgress(getProgressType() == ProgressType.KNOWN ? 0 : -1);
state.setTitle(name);
state.setState(SActionState.STARTED);
state.setStart(runningService.getStartDate());
bimServerClientInterface.getRegistry().updateProgressTopic(topicId, state);
AbstractService.this.newRevision(runningService, bimServerClientInterface, poid, roid, userToken, soid, settings);
state = new SLongActionState();
state.setProgress(100);
state.setTitle(name);
state.setState(SActionState.FINISHED);
state.setStart(runningService.getStartDate());
state.setEnd(new Date());
bimServerClientInterface.getRegistry().updateProgressTopic(topicId, state);
} catch (BimServerClientException e) {
LOGGER.error("", e);
} catch (Exception e) {
LOGGER.error("", e);
} finally {
bimServerClientInterface.getRegistry().unregisterProgressTopic(topicId);
}
} catch (PublicInterfaceNotFoundException e) {
LOGGER.error("", e);
}
}
});
}
use of org.bimserver.interfaces.objects.SObjectType in project BIMserver by opensourceBIM.
the class InternalServicesManager method getBimServerClient.
private P getBimServerClient(String serviceIdentifier, String profileIdentifier, String apiUrl, String token) {
ServiceMapInterface serviceMapInterface = new ServiceMap(bimServer, null, AccessMethod.JSON, null);
serviceMapInterface.add(RemoteServiceInterface.class, internalRemoteServiceInterfaces.get(serviceIdentifier));
P p = new P();
final InternalChannel internalChannel = new InternalChannel(bimServer.getServiceFactory(), bimServer.getServicesMap());
try {
internalChannel.connect(new SimpleTokenHolder());
} catch (ChannelConnectionException e) {
LOGGER.error("", e);
}
try {
DatabaseSession session = bimServer.getDatabase().createSession(OperationType.READ_ONLY);
try {
long profileId = Long.parseLong(profileIdentifier);
EClass eClassForOid = session.getEClassForOid(profileId);
InternalServicePluginConfiguration internalServicePluginConfiguration = null;
if (eClassForOid == StorePackage.eINSTANCE.getInternalServicePluginConfiguration()) {
internalServicePluginConfiguration = session.get(profileId, OldQuery.getDefault());
} else if (eClassForOid == StorePackage.eINSTANCE.getService()) {
Service service = session.get(profileId, OldQuery.getDefault());
internalServicePluginConfiguration = service.getInternalService();
} else {
throw new RuntimeException("Oid is neither an InternalServicePluginConfiguration nor a Service");
}
final SObjectType settings = bimServer.getSConverter().convertToSObject(internalServicePluginConfiguration.getSettings());
BimServerClientInterface bimServerClient = null;
BimServerClientFactory factory = null;
if (apiUrl == null) {
factory = bimServer.getBimServerClientFactory();
} else {
if (factories.containsKey(apiUrl)) {
factory = factories.get(apiUrl);
} else {
factory = new JsonBimServerClientFactory(apiUrl, bimServer.getServicesMap(), new JsonSocketReflectorFactory(bimServer.getServicesMap()), bimServer.getReflectorFactory(), bimServer.getMetaDataManager());
factories.put(apiUrl, factory);
}
}
bimServerClient = factory.create(new TokenAuthentication(token));
p.client = bimServerClient;
p.settings = settings;
return p;
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} catch (ServiceException e) {
LOGGER.error("", e);
} catch (ChannelConnectionException e) {
LOGGER.error("", e);
} finally {
session.close();
}
} finally {
}
return null;
}
Aggregations