Skip to content

Commit

Permalink
add connectorSubscribed
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Mar 23, 2024
1 parent 8fc1829 commit dc59352
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
public class MappingSubscribed implements Serializable {
public MappingSubscribed(String ident) {
this.ident = ident;
this.connectorSubscribed = new ArrayList<>();
this.connectorsSubscribed = new ArrayList<>();
}

@NotNull
public String ident;
@NotNull
public ArrayList<ConnectorConfiguration> connectorSubscribed;
public ArrayList<ConnectorConfiguration> connectorsSubscribed;
}
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ public ResponseEntity<Map<String, Integer>> getActiveSubscriptions(@PathVariable

}

@RequestMapping(value = "/monitoring/mappings", method = RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/mappingSubscribed", method = RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String,MappingSubscribed>> getMappingsSubscribed() {
String tenant = contextService.getContext().getTenant();
Map<String,MappingSubscribed> mappingsSubscribed = new HashMap<>();
Expand All @@ -467,7 +467,7 @@ public ResponseEntity<Map<String,MappingSubscribed>> getMappingsSubscribed() {
List<String> subscribedMappings = client.getSubscribedMappings();
subscribedMappings.forEach(ident -> {
MappingSubscribed mappingSubscribed = mappingsSubscribed.getOrDefault(ident, new MappingSubscribed(ident));
mappingSubscribed.getConnectorSubscribed().add(cleanedConfiguration);
mappingSubscribed.getConnectorsSubscribed().add(cleanedConfiguration);
mappingsSubscribed.put(ident, mappingSubscribed);
});
}
Expand Down
2 changes: 1 addition & 1 deletion dynamic-mapping-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"scripts": {
"start": "ng serve --host 0.0.0.0",
"start:admin": "npm start -- --shell administration -u https://ck2.eu-latest.cumulocity.com",
"start:admin": "npm start -- --shell administration -u https://mqttservice.latest.stage.c8y.io",
"build": "ng build",
"deploy": "ng deploy",
"format": "prettier --write 'src/**/*.ts'",
Expand Down
43 changes: 29 additions & 14 deletions dynamic-mapping-ui/src/mapping/core/mapping.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ import {
PATH_SUBSCRIPTION_ENDPOINT,
Direction,
Mapping,
SharedService
SharedService,
MappingSubscribed,
PATH_MAPPING_SUBSCRIBED_ENDPOINT
} from '../../shared';
import { JSONProcessorInbound } from '../processor/impl/json-processor-inbound.service';
import { JSONProcessorOutbound } from '../processor/impl/json-processor-outbound.service';
Expand Down Expand Up @@ -80,6 +82,22 @@ export class MappingService {
this._mappingsOutbound = undefined;
}

async getMappingsSubscribed(): Promise<MappingSubscribed[]> {
const response = this.client.fetch(
`${BASE_URL}/${PATH_MAPPING_SUBSCRIBED_ENDPOINT}`,
{
headers: {
'content-type': 'application/json'
},
method: 'GET'
}
);
const data = await response;
if (!data.ok) throw new Error(data.statusText)!;
const mappings: Promise<MappingSubscribed[]> = await data.json();
return mappings;
}

async getMappings(direction: Direction): Promise<Mapping[]> {
let mappings: Promise<Mapping[]>;
if (
Expand All @@ -89,23 +107,20 @@ export class MappingService {
const result: Mapping[] = [];
const filter: object = {
pageSize: 200,
withTotalPages: true,
withTotalPages: true
};
const query: any = {
__and: [
{ 'd11r_mapping.direction': direction },
{ 'type': MAPPING_TYPE }
]
__and: [{ 'd11r_mapping.direction': direction }, { type: MAPPING_TYPE }]
};

// if (direction == Direction.INBOUND) {
// query = this.queriesUtil.addOrFilter(query, {
// __not: { __has: 'd11r_mapping.direction' }
// });
// }
// query = this.queriesUtil.addAndFilter(query, {
// type: { __has: 'd11r_mapping' }
// });
// if (direction == Direction.INBOUND) {
// query = this.queriesUtil.addOrFilter(query, {
// __not: { __has: 'd11r_mapping.direction' }
// });
// }
// query = this.queriesUtil.addAndFilter(query, {
// type: { __has: 'd11r_mapping' }
// });

const { data } = await this.inventory.listQuery(query, filter);

Expand Down
4 changes: 2 additions & 2 deletions dynamic-mapping-ui/src/mapping/grid/mapping.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
[selectable]="'true'"
[columns]="columnsMappings"
[bulkActionControls]="bulkActionControls"
[rows]="mappings"
[rows]=" mappings$ |async"
[pagination]="pagination"
[actionControls]="actionControls"
>
Expand Down Expand Up @@ -114,7 +114,7 @@ <h1 [c8yIcon]="'file-text'"></h1>
>
<div class="card-block">
<c8y-data-grid
[title]="titleSubsription | translate"
[title]="titleSubscription | translate"
[columns]="columnsSubscriptions"
[rows]="subscription?.devices"
[pagination]="pagination"
Expand Down
82 changes: 55 additions & 27 deletions dynamic-mapping-ui/src/mapping/grid/mapping.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@
*
* @authors Christof Strack
*/
import {
Component,
OnDestroy,
OnInit,
ViewEncapsulation
} from '@angular/core';
import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
import {
ActionControl,
AlertService,
Expand All @@ -42,6 +37,7 @@ import {
ConfirmationModalComponent,
Direction,
Mapping,
MappingEnriched,
MappingSubstitution,
MappingType,
QOS,
Expand All @@ -54,7 +50,7 @@ import {
import { Router } from '@angular/router';
import { IIdentified } from '@c8y/client';
import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal';
import { Subject } from 'rxjs';
import { Subject, BehaviorSubject } from 'rxjs';
import { MappingService } from '../core/mapping.service';
import { ImportMappingsComponent } from '../import-modal/import.component';
import { MappingTypeComponent } from '../mapping-type/mapping-type.component';
Expand All @@ -66,6 +62,7 @@ import { StatusRendererComponent } from '../renderer/status-cell.renderer.compon
// import { TemplateRendererComponent } from '../renderer/template.renderer.component';
import { EditorMode, StepperConfiguration } from '../step-main/stepper-model';
import { C8YAPISubscription, PayloadWrapper } from '../shared/mapping.model';
import { ConnectorsSubscribedRendererComponent } from '../renderer/connectorSubsribed.renderer.component';

@Component({
selector: 'd11r-mapping-mapping-grid',
Expand All @@ -81,7 +78,8 @@ export class MappingComponent implements OnInit, OnDestroy {

isConnectionToMQTTEstablished: boolean;

mappings: Mapping[] = [];
mappings: MappingEnriched[] = [];
mappings$: BehaviorSubject<MappingEnriched[]> = new BehaviorSubject([]);
mappingToUpdate: Mapping;
subscription: C8YAPISubscription;
devices: IIdentified[] = [];
Expand All @@ -100,7 +98,7 @@ export class MappingComponent implements OnInit, OnDestroy {
direction: Direction.INBOUND
};
titleMapping: string;
titleSubsription: string = 'Subscription on devices for mapping OUTBOUND';
titleSubscription: string = 'Subscription on devices for mapping OUTBOUND';

displayOptions: DisplayOptions = {
bordered: true,
Expand All @@ -113,7 +111,7 @@ export class MappingComponent implements OnInit, OnDestroy {
{
name: 'name',
header: 'Name',
path: 'name',
path: 'mapping.name',
filterable: false,
dataType: ColumnDataType.TextShort,
cellRendererComponent: NameRendererComponent,
Expand All @@ -123,19 +121,19 @@ export class MappingComponent implements OnInit, OnDestroy {
{
header: 'Subscription Topic',
name: 'subscriptionTopic',
path: 'subscriptionTopic',
path: 'mapping.subscriptionTopic',
filterable: true
},
{
header: 'Template Topic',
name: 'templateTopic',
path: 'templateTopic',
path: 'mapping.templateTopic',
filterable: true
},
{
name: 'targetAPI',
header: 'API',
path: 'targetAPI',
path: 'mapping.targetAPI',
filterable: true,
sortable: true,
dataType: ColumnDataType.TextShort,
Expand All @@ -158,10 +156,18 @@ export class MappingComponent implements OnInit, OnDestroy {
// sortable: false,
// cellRendererComponent: TemplateRendererComponent
// },
{
header: 'Connectors',
name: 'connectors',
path: 'connectorsSubscribed',
filterable: true,
sortable: false,
cellRendererComponent: ConnectorsSubscribedRendererComponent
},
{
header: 'Test/Snoop',
name: 'tested',
path: 'tested',
path: 'mapping.tested',
filterable: false,
sortable: false,
cellRendererComponent: StatusRendererComponent,
Expand All @@ -171,15 +177,15 @@ export class MappingComponent implements OnInit, OnDestroy {
{
header: 'QOS',
name: 'qos',
path: 'qos',
path: 'mapping.qos',
filterable: true,
sortable: false,
cellRendererComponent: QOSRendererComponent
},
{
header: 'Active',
name: 'active',
path: 'active',
path: 'mapping.active',
filterable: false,
sortable: true,
cellRendererComponent: StatusActivationRendererComponent,
Expand Down Expand Up @@ -256,9 +262,9 @@ export class MappingComponent implements OnInit, OnDestroy {
this.subscription = await this.mappingService.getSubscriptions();
}

async ngOnInit() {
ngOnInit() {
// console.log('ngOnInit');
this.getMappings();
this.init();
this.actionControls.push(
{
type: BuiltInActionType.Edit,
Expand Down Expand Up @@ -524,14 +530,30 @@ export class MappingComponent implements OnInit, OnDestroy {
}

async getMappings(): Promise<void> {
this.mappings = await this.mappingService.getMappings(
const mappingsPromise = this.mappingService.getMappings(
this.stepperConfiguration.direction
);
const mappingsSubscribedPromise =
this.mappingService.getMappingsSubscribed();
Promise.all([mappingsPromise, mappingsSubscribedPromise]).then(
(results) => {
const mappingsEnriched = [];
const [mappings, mappingsSubscribed] = results;
mappings.forEach((m) => {
mappingsEnriched.push({
id: m.id,
mapping: m,
connectorsSubscribed: mappingsSubscribed[m.ident]
});
});
this.mappings$.next(mappingsEnriched);
}
);
}

async reloadMappings(): Promise<void> {
this.mappingService.resetCache();
this.getMappings();
await this.getMappings();
}

async onCommitMapping(mapping: Mapping) {
Expand Down Expand Up @@ -625,14 +647,16 @@ export class MappingComponent implements OnInit, OnDestroy {
}

private exportMappingBulk(ids: string[]) {
const mappings2Export = this.mappings.filter((m) => ids.includes(m.id));
const mappings2Export = this.mappings
.map((m) => m.mapping)
.filter((m) => ids.includes(m.id));
this.exportMappings(mappings2Export);
}

private async activateMappingBulk(ids: string[]) {
for (let i = 0; i < this.mappings.length; i++) {
if (ids.includes(this.mappings[i].id)) {
const newActive = !this.mappings[i].active;
const newActive = !this.mappings[i].mapping.active;
const action = newActive ? 'Activate' : 'Deactivate';
const parameter = { id: this.mappings[i].id, active: newActive };
await this.mappingService.changeActivationMapping(parameter);
Expand All @@ -648,12 +672,12 @@ export class MappingComponent implements OnInit, OnDestroy {
if (ids.includes(this.mappings[i].id)) {
if (i == 0) {
continueDelete = await this.deleteMappingWithConfirmation(
this.mappings[i],
this.mappings[i].mapping,
true,
true
);
} else if (continueDelete) {
await this.deleteMapping(this.mappings[i]);
await this.deleteMapping(this.mappings[i].mapping);
}
}
}
Expand All @@ -662,9 +686,9 @@ export class MappingComponent implements OnInit, OnDestroy {
}

async onExportAll() {
const mappings2Export = this.mappings.filter(
(m) => m.direction == this.stepperConfiguration.direction
);
const mappings2Export = this.mappings
.map((m) => m.mapping)
.filter((m) => m.direction == this.stepperConfiguration.direction);
this.exportMappings(mappings2Export);
}

Expand Down Expand Up @@ -727,4 +751,8 @@ export class MappingComponent implements OnInit, OnDestroy {
this.destroy$.next(true);
this.destroy$.unsubscribe();
}

async init() {
await this.getMappings();
}
}
2 changes: 2 additions & 0 deletions dynamic-mapping-ui/src/mapping/mapping.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { MappingStepPropertiesComponent } from './step-one/mapping-properties.co
import { MappingStepTestingComponent } from './step-three/mapping-testing.component';
import { MappingSubscriptionComponent } from './subscription/mapping-subscription.component';
import { WrapperCustomFormField } from './shared/formly/custom-form-field.wrapper.component';
import { ConnectorsSubscribedRendererComponent } from './renderer/connectorSubsribed.renderer.component';

@NgModule({
declarations: [
Expand All @@ -63,6 +64,7 @@ import { WrapperCustomFormField } from './shared/formly/custom-form-field.wrappe
EditSubstitutionComponent,
ImportMappingsComponent,
StatusRendererComponent,
ConnectorsSubscribedRendererComponent,
QOSRendererComponent,
TemplateRendererComponent,
SnoopedTemplateRendererComponent,
Expand Down
Loading

0 comments on commit dc59352

Please sign in to comment.