Skip to content

Commit

Permalink
see #160 : revert agentId allowed to null
Browse files Browse the repository at this point in the history
  • Loading branch information
guillermau committed Nov 18, 2024
1 parent c30250a commit 2b332f8
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export const createGetCompiledData = (db: Kysely<Database>) => async (): Promise
}): CompiledData.Software<"private"> => {
return {
...stripNullOrUndefinedValues(software),
addedByAgentEmail: addedByAgentId ? agentById[addedByAgentId].email : undefined,
addedByAgentEmail: agentById[addedByAgentId].email,
updateTime: new Date(+updateTime).getTime(),
referencedSinceTime: new Date(+referencedSinceTime).getTime(),
doRespectRgaa,
Expand Down
2 changes: 1 addition & 1 deletion api/src/core/adapters/dbApi/kysely/kysely.database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ type SoftwaresTable = {
>;
categories: JSONColumnType<string[]>;
generalInfoMd: string | null;
addedByAgentId: number | null;
addedByAgentId: number;
logoUrl: string | null;
keywords: JSONColumnType<string[]>;
};
Expand Down

This file was deleted.

9 changes: 3 additions & 6 deletions api/src/core/adapters/hal/getHalSoftware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,10 @@ export async function fetchHalSoftwares(): Promise<Array<HalRawSoftware>> {
// Filter only software who have an swhidId to filter clean data on https://hal.science, TODO remove and set it as an option to be generic
const url = `https://api.archives-ouvertes.fr/search/?q=docType_s:SOFTWARE&rows=10000&fl=${halSoftwareFieldsToReturnAsString}&&fq=swhidId_s:["" TO *]`;

const res = await fetch(url).catch(() => undefined);

console.debug("Hal response status : ", res?.status);

if (res === undefined) {
const res = await fetch(url).catch((err) => {
console.error(err);
throw new HalFetchError(undefined);
}
});

if (res.status === 429) {
await new Promise(resolve => setTimeout(resolve, 100));
Expand Down
48 changes: 19 additions & 29 deletions api/src/core/adapters/hal/halRawSoftware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,8 @@ const halSoftwareFieldsToReturn: (keyof HalRawSoftware)[] = [
export const halSoftwareFieldsToReturnAsString = halSoftwareFieldsToReturn.join(",");

export const rawHalSoftwareToSoftwareExternalData = (halSoftware: HalRawSoftware): SoftwareExternalData => {
let bibliographicReferences = undefined;
try {
bibliographicReferences = parseBibliographicFields(halSoftware.label_bibtex);
} catch (error) {
console.error('HalRawSoftwareToSoftwareForm', error);
}
const license = bibliographicReferences && bibliographicReferences.license ? bibliographicReferences.license.join(", ") : undefined;
const bibliographicReferences = parseBibliographicFields(halSoftware.label_bibtex);
const license = bibliographicReferences?.license.join(", ");

const developers = bibliographicReferences && bibliographicReferences.author ? bibliographicReferences.author.map(author => ({
id: author.toLowerCase().split(" ").join("-"),
Expand Down Expand Up @@ -85,9 +80,9 @@ export type HalRawSoftware = {
title_s: string[];
en_title_s?: string[];
fr_title_s?: string[];
abstract_s?: string[]; // 1030 / 1398
en_abstract_s?: string[]; // 896 / 1398
fr_abstract_s?: string[]; // 235 / 1398
abstract_s?: string[];
en_abstract_s?: string[];
fr_abstract_s?: string[];
uri_s: string;
openAccess_bool: boolean;
docType_s: string;
Expand All @@ -109,9 +104,9 @@ export type HalRawSoftware = {
// es_domainAllCodeLabel_fs: string[];
// eu_domainAllCodeLabel_fs: string[];
// primaryDomain_s: string;
// en_keyword_s?: string[]; // 711 / 1398
// keyword_s: string[]; // 786 / 1398
// fr_keyword_s?: string[]; // 184 / 1398
// en_keyword_s?: string[];
// keyword_s: string[];
// fr_keyword_s?: string[];
// authIdFormPerson_s: string[];
// authIdForm_i: number[];
// authLastName_s: string[];
Expand Down Expand Up @@ -166,7 +161,7 @@ export type HalRawSoftware = {
// contributorFullName_s: string;
// contributorIdFullName_fs: string;
// contributorFullNameId_fs: string;
// language_s: string[]; // Could use
// language_s: string[];
// halId_s: string;
// version_i: number;
// status_i: number;
Expand Down Expand Up @@ -216,28 +211,23 @@ export type HalRawSoftware = {
// collCategoryCodeName_fs: string[];
// collNameCode_fs: string[];
// fileMain_s: string;
// files_s: string[]; // Could ontains zip code
// files_s: string[];
// fileType_s: string[];
// _version_: bigint;
// dateLastIndexed_tdate: string;
// label_xml: string;
// softCodeRepository_s: string[]; // 727 / 1398
// softDevelopmentStatus_s: string[]; // 715 / 1398
// softPlatform_s:string[]; // 449 / 1398
// softProgrammingLanguage_s: string[]; // 929 / 1398
// softRuntimePlatform_s: string[]; // 195 / 1398
// softVersion_s: string[]; // 642 / 1398
// licence_s: string[]; // default licencse ? -> 20 / 1398
// softCodeRepository_s: string[];
// softDevelopmentStatus_s: string[];
// softPlatform_s:string[];
// softProgrammingLanguage_s: string[];
// softRuntimePlatform_s: string[];
// softVersion_s: string[];
// licence_s: string[];
};

export const HalRawSoftwareToSoftwareForm = (halSoftware: HalRawSoftware): SoftwareFormData => {
let bibliographicReferences = undefined;
try {
bibliographicReferences = parseBibliographicFields(halSoftware.label_bibtex);
} catch (error) {
console.error('HalRawSoftwareToSoftwareForm', error);
}
const license = bibliographicReferences && bibliographicReferences.license ?bibliographicReferences.license.join(", ") : undefined;
const bibliographicReferences = parseBibliographicFields(halSoftware.label_bibtex);
const license = bibliographicReferences?.license.join(", ");

// TODO Mapping
const formData : SoftwareFormData = {
Expand Down
2 changes: 1 addition & 1 deletion api/src/core/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export async function bootstrapCore(
await initializeUserApiCache();
}

if (config.feedFromSource) {
if (config.initializeSoftwareFromSource) {
if (config.externalSoftwareDataOrigin === 'HAL') {
console.log(' ------ Feeding database with HAL software started ------');
const HAL = feedDBfromHAL(dbApi);
Expand Down
2 changes: 1 addition & 1 deletion api/src/core/ports/CompileData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export namespace CompiledData {
};

export type Private = Common & {
addedByAgentEmail: string | undefined;
addedByAgentEmail: string;
users: (Pick<Db.AgentRow, "organization"> &
Pick<Db.SoftwareUserRow, "os" | "serviceUrl" | "useCaseDescription" | "version">)[];
referents: (Pick<Db.AgentRow, "email" | "organization"> &
Expand Down
4 changes: 2 additions & 2 deletions api/src/core/ports/DbApiV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export interface SoftwareRepository {
params: {
formData: SoftwareFormData;
externalDataOrigin: ExternalDataOrigin;
} & (WithAgentId | {agentId : undefined})
} & WithAgentId
) => Promise<number>;
update: (
params: {
softwareSillId: number;
formData: SoftwareFormData;
} & (WithAgentId | {agentId : undefined})
} & WithAgentId
) => Promise<void>;
updateLastExtraDataFetchAt: (params: { softwareId: number }) => Promise<void>;
getAll: (filters?: GetSoftwareFilters) => Promise<Software[]>;
Expand Down
2 changes: 1 addition & 1 deletion api/src/core/usecases/feedDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const feedDBfromHAL : any = (dbApi : DbApiV2) => {
return Promise.resolve(soft.id);
} else {
console.log('Importing HAL : ', software.docid);
return dbApi.software.create({ formData: newSoft, externalDataOrigin: 'HAL', agentId: undefined });
return dbApi.software.create({ formData: newSoft, externalDataOrigin: 'HAL', agentId: 1 }); // TODO agent id
}
});
}
Expand Down
14 changes: 7 additions & 7 deletions api/src/core/usecases/readWriteSillData/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,17 @@ export type SoftwareFormData = {
softwareName: string;
softwareDescription: string;
softwareType: SoftwareType;
externalId: string | undefined; // Id
comptoirDuLibreId: number | undefined; // id on the library comptoir du libre
softwareLicense: string; // or default licence ?
externalId: string | undefined;
comptoirDuLibreId: number | undefined;
softwareLicense: string;
softwareMinimalVersion: string;
similarSoftwareExternalDataIds: string[]; //
similarSoftwareExternalDataIds: string[];
softwareLogoUrl: string | undefined;
softwareKeywords: string[];

isPresentInSupportContract: boolean; // ??
isFromFrenchPublicService: boolean; // Financed and developped by public service
doRespectRgaa: boolean | null; // référentiel général d’amélioration de l’accessibilité
isPresentInSupportContract: boolean;
isFromFrenchPublicService: boolean;
doRespectRgaa: boolean | null;
};

export type DeclarationFormData = DeclarationFormData.User | DeclarationFormData.Referent;
Expand Down
4 changes: 2 additions & 2 deletions api/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const zConfiguration = z.object({
"redirectUrl": z.string().optional(),
"externalSoftwareDataOrigin": z.enum(["wikidata", "HAL"]).optional(),
"databaseUrl": z.string(),
"feedFromSource": z.boolean(),
"initializeSoftwareFromSource": z.boolean(),
});

const getJsonConfiguration = () => {
Expand Down Expand Up @@ -67,7 +67,7 @@ const getJsonConfiguration = () => {
"externalSoftwareDataOrigin": process.env.SILL_EXTERNAL_SOFTWARE_DATA_ORIGIN,
"redirectUrl": process.env.SILL_REDIRECT_URL,
"databaseUrl": process.env.DATABASE_URL,
"feedFromSource": process.env.FEEDFROMSOURCE ? process.env.FEEDFROMSOURCE.toLowerCase() == "true" : false,
"initializeSoftwareFromSource": process.env?.INITSOFTFROMSOURCE?.toLowerCase() === "true",
};
};

Expand Down
1 change: 1 addition & 0 deletions deployments/docker-compose-example/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ SILL_GITHUB_TOKEN=xxxxx
SILL_API_PORT=3084
SILL_IS_DEV_ENVIRONNEMENT=true
SILL_EXTERNAL_SOFTWARE_DATA_ORIGIN=wikidata
INITSOFTFROMSOURCE=false

DATABASE_URL=postgresql://sill:pg_password@localhost:5432/sill
POSTGRES_DB=sill
Expand Down

0 comments on commit 2b332f8

Please sign in to comment.