2022-03-07 11:04:02 +05:30
|
|
|
/*
|
2022-12-27 12:37:58 +05:30
|
|
|
* Copyright 2022 Collate.
|
2022-03-07 11:04:02 +05:30
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { AxiosResponse } from 'axios';
|
|
|
|
import { Operation } from 'fast-json-patch';
|
2023-11-16 18:56:38 +03:00
|
|
|
import { PagingResponse } from 'Models';
|
2024-02-16 10:23:36 +05:30
|
|
|
import { VotingDataProps } from '../components/Entity/Voting/voting.interface';
|
2024-04-26 12:55:40 +05:30
|
|
|
import { PAGE_SIZE_MEDIUM } from '../constants/constants';
|
|
|
|
import { SearchIndex } from '../enums/search.enum';
|
2023-12-03 00:57:03 +05:30
|
|
|
import { AddGlossaryToAssetsRequest } from '../generated/api/addGlossaryToAssetsRequest';
|
2022-03-07 11:04:02 +05:30
|
|
|
import { CreateGlossary } from '../generated/api/data/createGlossary';
|
|
|
|
import { CreateGlossaryTerm } from '../generated/api/data/createGlossaryTerm';
|
2023-12-03 00:57:03 +05:30
|
|
|
import { EntityReference, Glossary } from '../generated/entity/data/glossary';
|
2022-08-08 18:29:05 +05:30
|
|
|
import { GlossaryTerm } from '../generated/entity/data/glossaryTerm';
|
2023-12-05 23:55:06 +05:30
|
|
|
import { BulkOperationResult } from '../generated/type/bulkOperationResult';
|
2024-02-26 14:52:17 +05:30
|
|
|
import { ChangeEvent } from '../generated/type/changeEvent';
|
2023-10-03 16:01:13 +05:30
|
|
|
import { CSVImportResult } from '../generated/type/csvImportResult';
|
|
|
|
import { EntityHistory } from '../generated/type/entityHistory';
|
2023-10-12 00:29:27 +05:30
|
|
|
import { ListParams } from '../interface/API.interface';
|
2024-01-11 14:23:33 +05:30
|
|
|
import { getEncodedFqn } from '../utils/StringsUtils';
|
2022-03-07 11:04:02 +05:30
|
|
|
import APIClient from './index';
|
|
|
|
|
2023-10-12 00:29:27 +05:30
|
|
|
export type ListGlossaryTermsParams = ListParams & {
|
2023-01-18 16:09:00 +05:30
|
|
|
glossary?: string;
|
|
|
|
parent?: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
const BASE_URL = '/glossaries';
|
|
|
|
|
2023-10-12 00:29:27 +05:30
|
|
|
export const getGlossariesList = async (params?: ListParams) => {
|
2023-01-18 16:09:00 +05:30
|
|
|
const response = await APIClient.get<PagingResponse<Glossary[]>>(BASE_URL, {
|
|
|
|
params,
|
|
|
|
});
|
2022-08-08 18:29:05 +05:30
|
|
|
|
|
|
|
return response.data;
|
2022-03-07 11:04:02 +05:30
|
|
|
};
|
|
|
|
|
2022-08-08 18:29:05 +05:30
|
|
|
export const addGlossaries = async (data: CreateGlossary) => {
|
2022-03-07 11:04:02 +05:30
|
|
|
const url = '/glossaries';
|
|
|
|
|
2022-08-08 18:29:05 +05:30
|
|
|
const response = await APIClient.post<
|
|
|
|
CreateGlossary,
|
|
|
|
AxiosResponse<Glossary>
|
|
|
|
>(url, data);
|
|
|
|
|
|
|
|
return response.data;
|
2022-03-07 11:04:02 +05:30
|
|
|
};
|
|
|
|
|
2022-08-08 18:29:05 +05:30
|
|
|
export const patchGlossaries = async (id: string, patch: Operation[]) => {
|
|
|
|
const response = await APIClient.patch<Operation[], AxiosResponse<Glossary>>(
|
|
|
|
`/glossaries/${id}`,
|
2024-01-27 00:19:00 +05:30
|
|
|
patch
|
2022-08-08 18:29:05 +05:30
|
|
|
);
|
|
|
|
|
|
|
|
return response.data;
|
2022-03-07 11:04:02 +05:30
|
|
|
};
|
|
|
|
|
2024-01-12 12:44:24 +05:30
|
|
|
export const getGlossariesByName = async (fqn: string, params?: ListParams) => {
|
2024-01-18 20:38:15 +05:30
|
|
|
const response = await APIClient.get<Glossary>(
|
|
|
|
`/glossaries/name/${getEncodedFqn(fqn)}`,
|
|
|
|
{
|
|
|
|
params,
|
|
|
|
}
|
|
|
|
);
|
2022-08-08 18:29:05 +05:30
|
|
|
|
|
|
|
return response.data;
|
2022-03-07 11:04:02 +05:30
|
|
|
};
|
|
|
|
|
2024-01-12 12:44:24 +05:30
|
|
|
export const getGlossariesById = async (id: string, params?: ListParams) => {
|
|
|
|
const response = await APIClient.get<Glossary>(`/glossaries/${id}`, {
|
|
|
|
params,
|
|
|
|
});
|
2023-06-24 11:32:17 +05:30
|
|
|
|
|
|
|
return response.data;
|
|
|
|
};
|
|
|
|
|
2023-01-18 16:09:00 +05:30
|
|
|
export const getGlossaryTerms = async (params: ListGlossaryTermsParams) => {
|
|
|
|
const response = await APIClient.get<PagingResponse<GlossaryTerm[]>>(
|
|
|
|
'/glossaryTerms',
|
|
|
|
{
|
|
|
|
params,
|
|
|
|
}
|
|
|
|
);
|
2022-03-07 11:04:02 +05:30
|
|
|
|
2023-01-18 16:09:00 +05:30
|
|
|
return response.data;
|
2022-03-07 11:04:02 +05:30
|
|
|
};
|
|
|
|
|
2024-01-12 12:44:24 +05:30
|
|
|
export const getGlossaryTermsById = async (id: string, params?: ListParams) => {
|
|
|
|
const response = await APIClient.get<GlossaryTerm>(`/glossaryTerms/${id}`, {
|
|
|
|
params,
|
|
|
|
});
|
2023-06-24 11:32:17 +05:30
|
|
|
|
|
|
|
return response.data;
|
2022-03-07 11:04:02 +05:30
|
|
|
};
|
|
|
|
|
2024-01-12 12:44:24 +05:30
|
|
|
export const getGlossaryTermByFQN = async (fqn = '', params?: ListParams) => {
|
|
|
|
const response = await APIClient.get<GlossaryTerm>(
|
|
|
|
`/glossaryTerms/name/${getEncodedFqn(fqn)}`,
|
|
|
|
{ params }
|
2022-03-07 11:04:02 +05:30
|
|
|
);
|
|
|
|
|
2022-08-08 18:29:05 +05:30
|
|
|
return response.data;
|
2022-03-07 11:04:02 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
export const addGlossaryTerm = (
|
|
|
|
data: CreateGlossaryTerm
|
|
|
|
): Promise<AxiosResponse> => {
|
|
|
|
const url = '/glossaryTerms';
|
|
|
|
|
|
|
|
return APIClient.post(url, data);
|
|
|
|
};
|
|
|
|
|
2022-08-08 18:29:05 +05:30
|
|
|
export const patchGlossaryTerm = async (id: string, patch: Operation[]) => {
|
2023-09-12 14:17:36 +05:30
|
|
|
const response = await APIClient.patch<
|
|
|
|
Operation[],
|
|
|
|
AxiosResponse<GlossaryTerm>
|
2024-01-27 00:19:00 +05:30
|
|
|
>(`/glossaryTerms/${id}`, patch);
|
2022-08-08 18:29:05 +05:30
|
|
|
|
|
|
|
return response.data;
|
2022-03-07 11:04:02 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
export const deleteGlossary = (id: string) => {
|
2022-06-08 23:04:41 +05:30
|
|
|
return APIClient.delete(`/glossaries/${id}?recursive=true&hardDelete=true`);
|
2022-03-07 11:04:02 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
export const deleteGlossaryTerm = (id: string) => {
|
2022-06-08 23:04:41 +05:30
|
|
|
return APIClient.delete(
|
|
|
|
`/glossaryTerms/${id}?recursive=true&hardDelete=true`
|
|
|
|
);
|
2022-03-07 11:04:02 +05:30
|
|
|
};
|
2023-01-17 21:02:35 +05:30
|
|
|
|
|
|
|
export const exportGlossaryInCSVFormat = async (glossaryName: string) => {
|
|
|
|
const response = await APIClient.get<string>(
|
2024-01-18 20:38:15 +05:30
|
|
|
`/glossaries/name/${getEncodedFqn(glossaryName)}/export`
|
2023-01-17 21:02:35 +05:30
|
|
|
);
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const importGlossaryInCSVFormat = async (
|
|
|
|
glossaryName: string,
|
|
|
|
data: string,
|
|
|
|
dryRun = true
|
|
|
|
) => {
|
|
|
|
const configOptions = {
|
|
|
|
headers: { 'Content-type': 'text/plain' },
|
|
|
|
};
|
|
|
|
const response = await APIClient.put<string, AxiosResponse<CSVImportResult>>(
|
2024-01-11 14:23:33 +05:30
|
|
|
`/glossaries/name/${getEncodedFqn(glossaryName)}/import?dryRun=${dryRun}`,
|
2023-01-17 21:02:35 +05:30
|
|
|
data,
|
|
|
|
configOptions
|
|
|
|
);
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
};
|
2023-03-29 09:52:41 +05:30
|
|
|
|
2023-04-08 15:26:43 +05:30
|
|
|
export const getGlossaryVersionsList = async (id: string) => {
|
2023-03-29 09:52:41 +05:30
|
|
|
const url = `/glossaries/${id}/versions`;
|
|
|
|
|
|
|
|
const response = await APIClient.get<EntityHistory>(url);
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
};
|
|
|
|
|
2023-04-08 15:26:43 +05:30
|
|
|
export const getGlossaryVersion = async (id: string, version: string) => {
|
|
|
|
const url = `/glossaries/${id}/versions/${version}`;
|
|
|
|
const response = await APIClient.get<Glossary>(url);
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getGlossaryTermsVersionsList = async (id: string) => {
|
2023-03-29 09:52:41 +05:30
|
|
|
const url = `/glossaryTerms/${id}/versions`;
|
|
|
|
|
|
|
|
const response = await APIClient.get<EntityHistory>(url);
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
};
|
2023-04-08 15:26:43 +05:30
|
|
|
|
|
|
|
export const getGlossaryTermsVersion = async (id: string, version: string) => {
|
|
|
|
const url = `/glossaryTerms/${id}/versions/${version}`;
|
|
|
|
|
|
|
|
const response = await APIClient.get<GlossaryTerm>(url);
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
};
|
2023-09-13 14:38:13 +05:30
|
|
|
|
|
|
|
export const updateGlossaryVotes = async (
|
|
|
|
id: string,
|
|
|
|
data: VotingDataProps
|
|
|
|
) => {
|
|
|
|
const response = await APIClient.put<
|
|
|
|
VotingDataProps,
|
2024-02-26 14:52:17 +05:30
|
|
|
AxiosResponse<ChangeEvent>
|
2023-09-13 14:38:13 +05:30
|
|
|
>(`/glossaries/${id}/vote`, data);
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const updateGlossaryTermVotes = async (
|
|
|
|
id: string,
|
|
|
|
data: VotingDataProps
|
|
|
|
) => {
|
|
|
|
const response = await APIClient.put<
|
|
|
|
VotingDataProps,
|
2024-02-26 14:52:17 +05:30
|
|
|
AxiosResponse<ChangeEvent>
|
2023-09-13 14:38:13 +05:30
|
|
|
>(`/glossaryTerms/${id}/vote`, data);
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
};
|
2023-12-03 00:57:03 +05:30
|
|
|
|
2023-12-05 23:55:06 +05:30
|
|
|
export const validateTagAddtionToGlossary = async (
|
|
|
|
glossaryTerm: GlossaryTerm,
|
|
|
|
dryRun = false
|
|
|
|
) => {
|
|
|
|
const data = {
|
|
|
|
dryRun: dryRun,
|
|
|
|
glossaryTags: glossaryTerm.tags ?? [],
|
|
|
|
};
|
|
|
|
|
|
|
|
const response = await APIClient.put<
|
|
|
|
AddGlossaryToAssetsRequest,
|
|
|
|
AxiosResponse<BulkOperationResult>
|
|
|
|
>(`/glossaryTerms/${glossaryTerm.id}/tags/validate`, data);
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
};
|
|
|
|
|
2023-12-03 00:57:03 +05:30
|
|
|
export const addAssetsToGlossaryTerm = async (
|
|
|
|
glossaryTerm: GlossaryTerm,
|
2023-12-05 23:55:06 +05:30
|
|
|
assets: EntityReference[],
|
|
|
|
dryRun = false
|
2023-12-03 00:57:03 +05:30
|
|
|
) => {
|
|
|
|
const data = {
|
|
|
|
assets: assets,
|
2023-12-05 23:55:06 +05:30
|
|
|
dryRun: dryRun,
|
2023-12-03 00:57:03 +05:30
|
|
|
glossaryTags: glossaryTerm.tags ?? [],
|
|
|
|
};
|
|
|
|
|
|
|
|
const response = await APIClient.put<
|
|
|
|
AddGlossaryToAssetsRequest,
|
|
|
|
AxiosResponse<GlossaryTerm>
|
|
|
|
>(`/glossaryTerms/${glossaryTerm.id}/assets/add`, data);
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const removeAssetsFromGlossaryTerm = async (
|
|
|
|
glossaryTerm: GlossaryTerm,
|
|
|
|
assets: EntityReference[]
|
|
|
|
) => {
|
|
|
|
const data = {
|
|
|
|
assets: assets,
|
|
|
|
dryRun: false,
|
|
|
|
glossaryTags: glossaryTerm.tags ?? [],
|
|
|
|
};
|
|
|
|
|
|
|
|
const response = await APIClient.put<
|
|
|
|
AddGlossaryToAssetsRequest,
|
|
|
|
AxiosResponse<GlossaryTerm>
|
|
|
|
>(`/glossaryTerms/${glossaryTerm.id}/assets/remove`, data);
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
};
|
2024-04-26 12:55:40 +05:30
|
|
|
|
|
|
|
export const searchGlossaryTerms = async (search: string, page = 1) => {
|
|
|
|
const apiUrl = `/search/query?q=*${search ?? ''}*`;
|
|
|
|
|
|
|
|
const { data } = await APIClient.get(apiUrl, {
|
|
|
|
params: {
|
|
|
|
index: SearchIndex.GLOSSARY_TERM,
|
|
|
|
from: (page - 1) * PAGE_SIZE_MEDIUM,
|
|
|
|
size: PAGE_SIZE_MEDIUM,
|
|
|
|
deleted: false,
|
|
|
|
track_total_hits: true,
|
|
|
|
getHierarchy: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
};
|
2024-04-30 12:42:43 +05:30
|
|
|
|
|
|
|
export type GlossaryTermWithChildren = Omit<GlossaryTerm, 'children'> & {
|
|
|
|
children?: GlossaryTerm[];
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getFirstLevelGlossaryTerms = async (parentFQN: string) => {
|
|
|
|
const apiUrl = `/glossaryTerms`;
|
|
|
|
|
|
|
|
const { data } = await APIClient.get<
|
|
|
|
PagingResponse<GlossaryTermWithChildren[]>
|
|
|
|
>(apiUrl, {
|
|
|
|
params: {
|
|
|
|
directChildrenOf: parentFQN,
|
|
|
|
fields: 'childrenCount',
|
|
|
|
limit: 100000,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
};
|