Skip to content

Commit

Permalink
MNES-1070 Implement Submodel Registry Api Client
Browse files Browse the repository at this point in the history
  • Loading branch information
XAlinaGS committed Jul 4, 2024
1 parent 64950ec commit e5e06ef
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/app/env/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const getEnv = async (): Promise<EnvironmentalVariables> => {
APPLICATION_ID_URI: process.env.APPLICATION_ID_URI,
DISCOVERY_API_URL: process.env.DISCOVERY_API_URL,
REGISTRY_API_URL: process.env.REGISTRY_API_URL,
SUBMODEL_REGISTRY_API_URL: process.env.SUBMODEL_REGISTRY_API_URL,
AAS_REPO_API_URL: process.env.AAS_REPO_API_URL,
MNESTIX_BACKEND_API_URL: process.env.MNESTIX_BACKEND_API_URL,
};
Expand Down Expand Up @@ -63,6 +64,7 @@ export type EnvironmentalVariables = {
AAS_LIST_FEATURE_FLAG: boolean;
DISCOVERY_API_URL: string | undefined;
REGISTRY_API_URL: string | undefined;
SUBMODEL_REGISTRY_API_URL: string | undefined;
AAS_REPO_API_URL: string | undefined;
MNESTIX_BACKEND_API_URL: string | undefined;
THEME_PRIMARY_COLOR: string | undefined;
Expand Down
1 change: 1 addition & 0 deletions src/app/env/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const initialValues: EnvironmentalVariables = {
APPLICATION_ID_URI: '',
DISCOVERY_API_URL: '',
REGISTRY_API_URL: '',
SUBMODEL_REGISTRY_API_URL: '',
AAS_REPO_API_URL: '',
MNESTIX_BACKEND_API_URL: '',
THEME_PRIMARY_COLOR: undefined,
Expand Down
2 changes: 2 additions & 0 deletions src/components/azureAuthentication/ApiProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ConfigurationShellApi } from 'lib/api/configuration-shell-api/configura
import { TemplateShellApi } from 'lib/api/template-shell-api/templateShellApi';
import { DiscoveryServiceApi } from 'lib/api/discovery-service-api/discoveryServiceApi';
import { RegistryServiceApi } from 'lib/api/registry-service-api/registryServiceApi';
import { SubmodelRegistryServiceApi } from 'lib/api/submodel-registry-service/submodelRegistryServiceApi';

const ApiContext = React.createContext<Apis | null>(null);
export const ApiProvider = (props: PropsWithChildren) => {
Expand All @@ -35,6 +36,7 @@ export const ApiProvider = (props: PropsWithChildren) => {
submodelClient: new SubmodelRepositoryApi({ basePath: env.AAS_REPO_API_URL }),
discoveryServiceClient: new DiscoveryServiceApi(env.DISCOVERY_API_URL),
registryServiceClient: new RegistryServiceApi(env.REGISTRY_API_URL),
submodelRegistryServiceClient: new SubmodelRegistryServiceApi(),
};

return <ApiContext.Provider value={apis}>{props.children}</ApiContext.Provider>;
Expand Down
125 changes: 125 additions & 0 deletions src/lib/api/submodel-registry-service/submodelRegistryServiceApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { SubmodelDescriptor } from 'lib/types/registryServiceTypes';
import { encodeBase64 } from 'lib/util/Base64Util';

export class SubmodelRegistryServiceApi {
baseUrl: string;

constructor(protected _baseUrl: string = '') {
this.baseUrl = _baseUrl;
}

public async getSubmodelDescriptorsById(submodelId: string) {
const b64_submodelId = encodeBase64(submodelId);

const headers = {
Accept: 'application/json',
};

const url = new URL(`${this.baseUrl}/submodel-descriptors/${b64_submodelId}`);

const response = await fetch(url, {
method: 'GET',
headers,
});

if (response.ok) {
return response.json();
} else {
throw response;
}
}

public async putSubmodelDescriptorsById(submodelId: string, submodelDescriptor: SubmodelDescriptor) {
const b64_submodelId = encodeBase64(submodelId);

const headers = {
Accept: 'application/json',
'Content-Type': 'application/json',
};

const url = new URL(`${this.baseUrl}/submodel-descriptors/${b64_submodelId}`);

const response = await fetch(url, {
method: 'PUT',
headers,
body: JSON.stringify(submodelDescriptor),
});

if (response.ok) {
return response.json();
} else {
throw response;
}
}

public async deleteSubmodelDescriptorsById(submodelId: string) {
const b64_submodelId = encodeBase64(submodelId);

const url = new URL(`${this.baseUrl}/submodel-descriptors/${b64_submodelId}`);

const response = await fetch(url, {
method: 'DELETE',
});

if (response.ok) {
return response;
} else {
throw response;
}
}

public async getAllSubmodelDescriptors() {
const headers = {
Accept: 'application/json',
};

const url = new URL(`${this.baseUrl}/submodel-descriptors`);

const response = await fetch(url, {
method: 'GET',
headers,
});

if (response.ok) {
return response.json();
} else {
throw response;
}
}

public async postSubmodelDescriptor(submodelDescriptor: SubmodelDescriptor) {
const headers = {
Accept: 'application/json',
'Content-Type': 'application/json',
};

const url = new URL(`${this.baseUrl}/submodel-descriptors`);

const response = await fetch(url, {
method: 'POST',
headers,
body: JSON.stringify(submodelDescriptor),
});

if (response.ok) {
return response.json();
} else {
throw response;
}
}

public async deleteAllSubmodelDescriptors() {
const url = new URL(`${this.baseUrl}/submodel-descriptors`);

const response = await fetch(url, {
method: 'DELETE',
});

if (response.ok) {
return response;
} else {
throw response;
}
}

}

0 comments on commit e5e06ef

Please sign in to comment.