generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: create adt services for ui-service generation (#1879)
* feat(service-api): test * Making everything more dynamic * feat(ui-service-gen): adt services for ui service generation, test flow in odata-cli * feat(ui-service-gen): code cleanup, add tests * better logging * feat(ui-service-gen): add more tests * changeset * feat(ui-service-gen): review comments * feat(ui-service-gen): odata-cli test update, changeset update * feat(ui-service-gen): update test * feat(ui-service-gen): cleanup * feat(ui-service-gen): cleanup * feat(ui-service-gen): cleanup changeset * feat(ui-service-gen): address review comment --------- Co-authored-by: Tobias Queck <tobias.queck@sap.com>
- Loading branch information
1 parent
f7f22b4
commit 312919e
Showing
26 changed files
with
6,350 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@sap-ux/axios-extension': minor | ||
'@sap-ux/odata-cli': patch | ||
--- | ||
|
||
Add new adt services for ui service generation and publish |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/axios-extension/src/abap/adt-catalog/generators/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export interface GeneratorEntry { | ||
id: string; | ||
link: { | ||
href: string; | ||
rel: string; | ||
type: string; | ||
}[]; | ||
} |
90 changes: 90 additions & 0 deletions
90
packages/axios-extension/src/abap/adt-catalog/generators/ui-service-generator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import type { Logger } from '@sap-ux/logger'; | ||
import type { GeneratorEntry } from './types'; | ||
import type { BusinessObject } from '../../types'; | ||
import { AdtService } from '../services'; | ||
|
||
/** | ||
* | ||
*/ | ||
export class UiServiceGenerator extends AdtService { | ||
public log: Logger; | ||
|
||
protected bo!: BusinessObject; | ||
|
||
/** | ||
* Configure the UI service generator. | ||
* | ||
* @param _config - The generator configuration. | ||
* @param bo - The business object. | ||
*/ | ||
public configure(_config: GeneratorEntry, bo: BusinessObject) { | ||
this.bo = bo; | ||
} | ||
|
||
/** | ||
* Get the content of the service binding. | ||
* | ||
* @param pckg - The package name. | ||
* @returns The content of the service binding. | ||
*/ | ||
public async getContent(pckg: string): Promise<string> { | ||
const response = await this.get('/content', { | ||
headers: { | ||
Accept: 'application/vnd.sap.adt.repository.generator.content.v1+json' | ||
}, | ||
params: { | ||
referencedObject: this.bo.uri, | ||
package: pckg | ||
} | ||
}); | ||
const content = response.data; | ||
const contentObj = JSON.parse(content); | ||
if (!contentObj['metadata']) { | ||
contentObj['metadata'] = { | ||
package: pckg | ||
}; | ||
} | ||
|
||
return JSON.stringify(contentObj); | ||
} | ||
|
||
/** | ||
* Generate the service binding. | ||
* | ||
* @param content - The content of the service binding. | ||
* @param transport - The transport. | ||
* @returns The object references. | ||
*/ | ||
public async generate(content: string, transport: string): Promise<any> { | ||
const response = await this.post('', content, { | ||
headers: { | ||
'Content-Type': 'application/vnd.sap.adt.repository.generator.content.v1+json', | ||
Accept: 'application/vnd.sap.adt.repository.generator.v1+json, application/vnd.sap.as+xml;charset=UTF-8;dataname=com.sap.adt.StatusMessage' | ||
}, | ||
params: { | ||
referencedObject: this.bo.uri, | ||
corrNr: transport | ||
} | ||
}); | ||
// Service binding is in XML format, ready to be used for the subsequent activation and publish. | ||
const data = this.parseResponse<any>(response.data); | ||
return data.objectReferences; | ||
} | ||
|
||
/** | ||
* Lock the service binding. The class should be configured with the uri of the service binding | ||
* The uri is returned from the generate method. | ||
*/ | ||
public async lockServiceBinding() { | ||
await this.post('', '', { | ||
headers: { | ||
Accept: 'application/*,application/vnd.sap.as+xml;charset=UTF-8;dataname=com.sap.adt.lock.result', | ||
'x-sap-adt-sessiontype': 'stateful' | ||
}, | ||
params: { | ||
_action: `LOCK`, | ||
accessMode: 'MODIFY' | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.