import java.util.ArrayList;
import java.util.List;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.impl.client.CloseableHttpClient;
boolean result = false;
HttpHead head = new HttpHead(plugin.getPluginDiscoveryUrl());
+ RequestConfig requestConfig = RequestConfig.custom()
+ .setSocketTimeout(1000)
+ .setConnectTimeout(1000)
+ .setConnectionRequestTimeout(1000).build();
+
+ head.setConfig(requestConfig);
try (CloseableHttpResponse response = this.client.execute(head)) {
result = response != null && response.getStatusLine().getStatusCode() == 200;
--- /dev/null
+declare const window: Window;
+
+export class BasePubSub {
+
+ subscribers: Map<string, ISubscriber>;
+ eventsCallbacks: Array<Function>;
+ clientId: string;
+
+ constructor(pluginId: string) {
+ this.subscribers = new Map<string, ISubscriber>();
+ this.eventsCallbacks = new Array<Function>();
+ this.clientId = pluginId;
+ this.onMessage = this.onMessage.bind(this);
+
+ window.addEventListener("message", this.onMessage);
+ }
+
+ public register(subscriberId: string, subscriberWindow: Window, subscriberUrl: string) {
+ const subscriber = {
+ window: subscriberWindow,
+ locationUrl: subscriberUrl || subscriberWindow.location.href
+ } as ISubscriber;
+
+ this.subscribers.set(subscriberId, subscriber);
+ }
+
+ public unregister(subscriberId: string) {
+ this.subscribers.delete(subscriberId);
+ }
+
+ public on(callback: Function) {
+ this.eventsCallbacks.push(callback);
+ }
+
+ public off(callback: Function) {
+ let index = this.eventsCallbacks.indexOf(callback);
+ this.eventsCallbacks.splice(index, 1)
+ }
+
+ public notify(eventType:string, eventData:any) {
+ let eventObj = {
+ type: eventType,
+ data: eventData,
+ originId: this.clientId
+ } as IPubSubEvent;
+
+ this.subscribers.forEach( (subscriber: ISubscriber, id: string) => {
+ subscriber.window.postMessage(eventObj, subscriber.locationUrl)
+ });
+ }
+
+ protected onMessage(event: any) {
+ if (this.subscribers.has(event.data.originId)) {
+ this.eventsCallbacks.forEach((callback: Function) => {
+ callback(event.data, event);
+ })
+ }
+ }
+}
+
+export class PluginPubSub extends BasePubSub {
+
+ constructor(pluginId: string, subscriberUrl: string) {
+ super(pluginId);
+ this.register('sdc-hub', window.parent, subscriberUrl);
+ this.subscribe();
+ }
+
+ public subscribe() {
+ const registerData = {
+ pluginId: this.clientId
+ };
+
+ this.notify('PLUGIN_REGISTER', registerData);
+ }
+
+ public unsubscribe() {
+ const unregisterData = {
+ pluginId: this.clientId
+ };
+
+ this.notify('PLUGIN_UNREGISTER', unregisterData);
+ }
+}
+
+export interface IPubSubEvent {
+ type: string;
+ originId: string;
+ data: any;
+}
+
+export interface ISubscriber {
+ window: Window;
+ locationUrl: string;
+}
import { TranslationServiceConfig } from "./config/translation.service.config";
import {PluginFrameModule} from "./components/ui/plugin/plugin-frame.module";
import {PluginsService} from "./services/plugins.service";
+import {EventBusService} from "./services/event-bus.service";
export const upgradeAdapter = new UpgradeAdapter(forwardRef(() => AppModule));
ComponentInstanceServiceNg2,
TranslationServiceConfig,
PluginsService,
+ EventBusService,
{
provide: APP_INITIALIZER,
useFactory: configServiceFactory,
export class AppModule {
- constructor(public upgrade:UpgradeModule) {
-
+ constructor(public upgrade:UpgradeModule, eventBusService:EventBusService) {
}
}
--- /dev/null
+import { Injectable } from '@angular/core';
+import {BasePubSub, IPubSubEvent} from "../../models/base-pubsub";
+
+@Injectable()
+export class EventBusService extends BasePubSub {
+
+ constructor() {
+ super("sdc-hub");
+ }
+
+ protected handlePluginRegistration(eventData: IPubSubEvent, event: any) {
+ if (eventData.type === 'PLUGIN_REGISTER') {
+ this.register(eventData.data.pluginId, event.source, event.origin);
+ } else if (eventData.type === 'PLUGIN_UNREGISTER') {
+ this.unregister(eventData.data.pluginId);
+ }
+ }
+
+ public unregister(pluginId: string) {
+ const unregisterData = {
+ pluginId: pluginId
+ };
+
+ this.notify('PLUGIN_CLOSE', unregisterData);
+ super.unregister(pluginId);
+ }
+
+ protected onMessage(event: any) {
+ if (event.data.type === 'PLUGIN_REGISTER') {
+ this.handlePluginRegistration(event.data, event);
+ }
+
+ super.onMessage(event);
+
+ if (event.data.type === 'PLUGIN_UNREGISTER') {
+ this.handlePluginRegistration(event.data, event);
+ }
+ }
+}
this.$scope.queryParams = {
userId: this.$scope.user.userId,
userRole: this.$scope.user.role,
- displayType: "tab"
+ displayType: "tab",
+ parentUrl: window.location.origin
};
}
}
contextType: this.$scope.component.getComponentSubType(),
uuid: this.$scope.component.uuid,
lifecycleState: this.$scope.component.lifecycleState,
- isOwner: this.$scope.component.lastUpdaterUserId === this.$scope.user.userId
+ isOwner: this.$scope.component.lastUpdaterUserId === this.$scope.user.userId,
+ version: this.$scope.component.version ,
+ parentUrl: window.location.origin
};
}
"ES": "yyy",
"KB": "yyy"
},
- "Designers": {
+ "Plugins": {
"DCAE": {
- "dcae_protocol": "yyy",
- "dcae_host": "yyy",
- "dcae_port": "yyy"
+ "dcae_discovery_url": "yyy",
+ "dcae_source_url": "yyy"
},
"WORKFLOW": {
- "workflow_protocol": "yyy",
- "workflow_host": "yyy",
- "workflow_port": "yyy"
+ "workflow_discovery_url": "yyy",
+ "workflow_source_url": "yyy"
}
- }
+ },
},
"override_attributes": {
"FE": {