Skip to content

Commit

Permalink
Merge pull request #147 from suvarnakale/main
Browse files Browse the repository at this point in the history
#849-Incorrect Credential Subject and JSONSchema is getting updated -…
  • Loading branch information
srprasanna authored Oct 23, 2023
2 parents d26e069 + 97f8cd7 commit b568a6b
Show file tree
Hide file tree
Showing 11 changed files with 331 additions and 272 deletions.
6 changes: 3 additions & 3 deletions src/app/admin/add-template/add-template.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ export class AddTemplateComponent implements OnInit {
<div class="line">
<div>Certified to</div>
<div>
<b>{{record.name}}</b>
<b>{{credentialSubject.name}}</b>
</div>
<div>issued on</div>
<div style="padding: 1em;font-family: 'Open Sans', sans-serif">
{{ credential.issuancedate}}
{{issuanceDate}}
</div>
<div>issued by </div>
<div>{{issuer.name}}</div>
<div>{{issuer}}</div>
</div>
</td>
</tr>
Expand Down
86 changes: 83 additions & 3 deletions src/app/admin/advance-editor/advance-editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Formio } from 'formiojs';
import { TranslateService } from '@ngx-translate/core';
import { editorConfig } from './advance-editor-config';
import { JsonEditorComponent, JsonEditorOptions } from 'ang-jsoneditor';

import { GeneralService } from 'src/app/services/general/general.service';
import { Output, EventEmitter } from '@angular/core';

@Component({
Expand All @@ -14,6 +14,7 @@ import { Output, EventEmitter } from '@angular/core';
})
export class AdvanceEditorComponent implements OnInit {
@Input() jsonSchema;
@Input() schemaOsid;
@ViewChild('json') jsonElement?: ElementRef;
public editorOptions: JsonEditorOptions;
public vcEditorOptions: JsonEditorOptions;
Expand All @@ -33,7 +34,10 @@ export class AdvanceEditorComponent implements OnInit {
isShowLessJson = false;
isShowLessVc = false;
isVcString = false;
constructor(public translate: TranslateService) {
certificateTitle: any;
schemaContent: any;

constructor(public translate: TranslateService, public generalService: GeneralService) {

this.editorOptions = new JsonEditorOptions();
this.editorOptions.mode = 'code';
Expand Down Expand Up @@ -91,7 +95,8 @@ export class AdvanceEditorComponent implements OnInit {
this.vcFields = jsonFields['_osConfig']['credentialTemplate'];
}

delete jsonFields['_osConfig']['credentialTemplate'];
// delete jsonFields['_osConfig']['credentialTemplate'];
this.vcFields = this.addCrtTemplateFields(jsonFields)
this.jsonFields = jsonFields;
this.jsonTitle = jsonFields['title'];
let jsonSchema = jsonFields.definitions[this.jsonTitle].properties;
Expand Down Expand Up @@ -120,6 +125,81 @@ export class AdvanceEditorComponent implements OnInit {

}

addCrtTemplateFields(credTempJson) {
this.schemaContent = credTempJson;
this.certificateTitle = credTempJson.title;
credTempJson['_osConfig']['credentialTemplate'] = {
"@context": [
"https://www.w3.org/2018/credentials/v1",
{
"@context": {
"@version": 1.1,
"@protected": true,
[this.certificateTitle]: {
"@id": "https://github.com/sunbird-specs/vc-specs#" + this.certificateTitle,
"@context": {
"id": "@id",
"@version": 1.1,
"@protected": true,
}
}
}
}
],
"type": [
"VerifiableCredential"
],
"issuanceDate": "2021-08-27T10:57:57.237Z",
"credentialSubject": {},
"issuer": "did:web:sunbirdrc.dev/vc/skill"
};

if (typeof (credTempJson) == 'string') {
let jsonUrl = credTempJson;

fetch(jsonUrl)
.then(response => response.text())
.then(data => {
});


} else {
credTempJson['_osConfig']['credentialTemplate']['credentialSubject'] = {};
credTempJson['_osConfig']['credentialTemplate']['credentialSubject']["type"] = this.certificateTitle;

if (this.schemaContent) {
let _self = this;
let properties = this.schemaContent.definitions[this.certificateTitle].properties;
for (const key in properties) {
if (properties.hasOwnProperty(key)) {
let propertyData = properties[key];
if (propertyData.type != 'object' && propertyData.type != 'array') {
credTempJson['_osConfig']['credentialTemplate']['credentialSubject'][key] = "{{" + propertyData["title"] + "}}"
} else {
let nestedPropertyData = properties[key].properties;
credTempJson['_osConfig']['credentialTemplate']['credentialSubject'][key] = {}
for (const keyName in nestedPropertyData) {
if (nestedPropertyData.hasOwnProperty(keyName)) {
let fieldData = nestedPropertyData[keyName];
if (fieldData.type != 'object' && fieldData.type != 'array') {
credTempJson['_osConfig']['credentialTemplate']['credentialSubject'][key][keyName] = "{{" + key + "." + fieldData["title"] + "}}"
}
}
}
}
}
}
}
};
let payload = {
"schema": JSON.stringify(credTempJson)
};
this.generalService.putData('/Schema', this.schemaOsid, payload).subscribe((res) => {
console.log(res);
});
return credTempJson['_osConfig']['credentialTemplate'];
}

nastedJsonSep(jsonSchema, key, definationName) {
if (jsonSchema[key].type == 'array') {
if (jsonSchema[key].items.hasOwnProperty('properties')) {
Expand Down
10 changes: 0 additions & 10 deletions src/app/admin/config-workflow/config-workflow.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ <h4>{{ entityName }}</h4>
<input class="w-100 br-4 border border-light fs-14 p-3" placeholder="Enter Workflow name" type="text"
required name="workflowname" formControlName="workflowname" />
</div>
<div class="mb-3">

<span class="fs-12 fw-bold">{{'SELECT_ISSUANCE_SYSTEM' | translate}}</span><br />
<select name="issuanceSystem" id="issuanceSystem" class="w-25 br-4 border-1 border-light fs-14 p-3"
formControlName="issuancesystem" [ngModel]="workflowForm.value.workflowItems[workflowIndex].issuancesystem">
{{workflow | json}}
<option value="" disabled hidden selected>{{'SELECT_FIELD' | translate}}</option>
<option value="sunbird_rc_issuance_system">Sunbird RC issuance system</option>
</select>
</div>
<div class="mb-3 d-flex">
<div class="form-check">
<input class="form-check-input" type="radio" [id]="'autoAttestation'+workflowIndex"
Expand Down
10 changes: 3 additions & 7 deletions src/app/admin/config-workflow/config-workflow.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ export class ConfigWorkflowComponent implements OnInit {
var data = {
workflowItems: [
{
workflowname: '',
issuancesystem: '',
workflowname: '',
attestation_type: '',
attestorConditions: [
{
Expand Down Expand Up @@ -270,8 +269,7 @@ export class ConfigWorkflowComponent implements OnInit {
this.setSelectOptions(l, 0, attestorEntity);
let workflowItems = [
{
workflowname: attestationPolicies[l].name,
issuancesystem: 'sunbird_rc_issuance_system',
workflowname: attestationPolicies[l].name,
attestation_type: attestationPolicies[l].type,
attestorConditions: [
{
Expand All @@ -296,7 +294,6 @@ export class ConfigWorkflowComponent implements OnInit {
workflowItems: [
{
workflowname: '',
issuancesystem: '',
attestation_type: '',
attestorConditions: [
{
Expand Down Expand Up @@ -346,8 +343,7 @@ export class ConfigWorkflowComponent implements OnInit {

newWorkflowItems(): FormGroup {
return this.fb.group({
workflowname: '',
issuancesystem: '',
workflowname: '',
attestation_type: '',
attestorConditions: this.fb.array([]),
additionalInput: {},
Expand Down
4 changes: 2 additions & 2 deletions src/app/admin/create-entity/create-entity.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ <h3>{{usecaseSchema[activeMenuNo]?.title}}</h3>
<p class="fs-14 text-grey-color">{{usecaseSchema[activeMenuNo]?.description}}</p>
</div>
<div *ngIf="!isShowJson && usecaseSchema[activeMenuNo]?.definitions?.data?.length">
<button class="float-end fw-bold fs-14 btn bg-color-secondary submit-button color-sec"
<!-- <button class="float-end fw-bold fs-14 btn bg-color-secondary submit-button color-sec"
(click)="showJson()" [disabled]="usecaseSchema[activeMenuNo]['status'] == 'PUBLISHED'">
<i class="fa fa-pencil-square-o" aria-hidden="true"></i> {{'JSON_SCHEMA' | translate}}
</button>
</button> -->
</div>
</div>

Expand Down
160 changes: 81 additions & 79 deletions src/app/admin/create-entity/create-entity.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1779,89 +1779,91 @@ export class CreateEntityComponent implements OnInit, AfterContentChecked {
if (!certTmpJson.isRefSchema) {
this.schemaContent = certTmpJson;
this.certificateTitle = certTmpJson.title;
certTmpJson['_osConfig']['credentialTemplate'] = {
"@context": [
"https://www.w3.org/2018/credentials/v1",
{
"@context": {
"@version": 1.1,
"@protected": true,
[this.certificateTitle]: {
"@id": "https://github.com/sunbird-specs/vc-specs#" + this.certificateTitle,
"@context": {
"id": "@id",
"@version": 1.1,
"@protected": true,
}
}
}
}
],
"type": [
"VerifiableCredential"
],
"issuanceDate": "2021-08-27T10:57:57.237Z",
"credentialSubject": {
"type": this.certificateTitle,
},
"issuer": "did:web:sunbirdrc.dev/vc/skill"
};

if (typeof (certTmpJson) == 'string') {
let jsonUrl = certTmpJson;

fetch(jsonUrl)
.then(response => response.text())
.then(data => {
});


} else {

certTmpJson['_osConfig']['credentialTemplate']['credentialSubject'] = {};

if (this.schemaContent) {
let _self = this;
let propertyData = this.schemaContent.definitions.data ? this.schemaContent.definitions.data : this.schemaContent.definitions;
// this.schemaContent._osConfig.credentialTemplate["@context"][1]["@context"][this.certificateTitle]["@context"] = {};
let contextProperty = this.schemaContent._osConfig.credentialTemplate["@context"][1]["@context"][this.certificateTitle]["@context"];


for (let i = 0; i < propertyData.length; i++) {
if (propertyData[i].type != 'object' && propertyData[i].type != 'array') {
if (propertyData[i].key != undefined) {
contextProperty[propertyData[i].key] = "schema:Text";
certTmpJson['_osConfig']['credentialTemplate']['credentialSubject'][contextProperty[propertyData[i].key]] = "{{" + contextProperty[propertyData[i].key] + "}}"
}
} else {
let stringKey = propertyData[i].propertyKey;
stringKey = stringKey.charAt(0).toLowerCase() + stringKey.slice(1);
contextProperty[stringKey] = {
"@id": "https://github.com/sunbird-specs/vc-specs#" + stringKey,
"@context": {
}
}
for (let j = 0; j < propertyData[i].data.length; j++) {
if (propertyData[i].data[j].type != 'object' && propertyData[i].data[j].type != 'array') {
let keyName = propertyData[i].data[j].key;

let stringKey = propertyData[i].propertyKey;
stringKey = stringKey.charAt(0).toLowerCase() + stringKey.slice(1);
if (stringKey != undefined && keyName != undefined) {

contextProperty[stringKey]["@context"][keyName] = "schema:Text";
certTmpJson['_osConfig']['credentialTemplate']['credentialSubject'][keyName] = "{{" + stringKey + "." + keyName + "}}"
}
}
}
}
}
certTmpJson['_osConfig']['credentialTemplate'] = {}
// certTmpJson['_osConfig']['credentialTemplate'] = {
// "@context": [
// "https://www.w3.org/2018/credentials/v1",
// {
// "@context": {
// "@version": 1.1,
// "@protected": true,
// [this.certificateTitle]: {
// "@id": "https://github.com/sunbird-specs/vc-specs#" + this.certificateTitle,
// "@context": {
// "id": "@id",
// "@version": 1.1,
// "@protected": true,
// }
// }
// }
// }
// ],
// "type": [
// "VerifiableCredential"
// ],
// "issuanceDate": "2021-08-27T10:57:57.237Z",
// "credentialSubject": {},
// "issuer": "did:web:sunbirdrc.dev/vc/skill"
// };

// if (typeof (certTmpJson) == 'string') {
// let jsonUrl = certTmpJson;

// fetch(jsonUrl)
// .then(response => response.text())
// .then(data => {
// });


// } else {

// certTmpJson['_osConfig']['credentialTemplate']['credentialSubject'] = {};
// certTmpJson['_osConfig']['credentialTemplate']['credentialSubject']["type"] = this.certificateTitle;

// if (this.schemaContent) {
// let _self = this;
// let propertyData = this.schemaContent.definitions.data ? this.schemaContent.definitions.data : this.schemaContent.definitions;
// // this.schemaContent._osConfig.credentialTemplate["@context"][1]["@context"][this.certificateTitle]["@context"] = {};
// let contextProperty = this.schemaContent._osConfig.credentialTemplate["@context"][1]["@context"][this.certificateTitle]["@context"];


// for (let i = 0; i < propertyData.length; i++) {
// if (propertyData[i].type != 'object' && propertyData[i].type != 'array') {
// if (propertyData[i].key != undefined) {
// contextProperty[propertyData[i].key] = "schema:Text";
// // certTmpJson['_osConfig']['credentialTemplate']['credentialSubject'][propertyData[i].key] = "{{" + propertyData[i].data["title"] + "}}"
// }
// } else {
// let stringKey = propertyData[i].propertyKey;
// stringKey = stringKey.charAt(0).toLowerCase() + stringKey.slice(1);
// contextProperty[stringKey] = {
// "@id": "https://github.com/sunbird-specs/vc-specs#" + stringKey,
// "@context": {
// }
// }
// for (let j = 0; j < propertyData[i].data.length; j++) {
// if (propertyData[i].data[j].type != 'object' && propertyData[i].data[j].type != 'array') {
// let key = propertyData[i].data[j].key;
// let keyName = propertyData[i].data[j].data["title"];

// let stringKey = propertyData[i].propertyKey;
// stringKey = stringKey.charAt(0).toLowerCase() + stringKey.slice(1);
// if (stringKey != undefined && keyName != undefined) {

// contextProperty[stringKey]["@context"][keyName] = "schema:Text";
// certTmpJson['_osConfig']['credentialTemplate']['credentialSubject'][stringKey] = {}
// certTmpJson['_osConfig']['credentialTemplate']['credentialSubject'][stringKey][key] = "{{" + stringKey + "." + keyName + "}}"
// }
// }
// }
// }
// }


let temp = JSON.stringify(certTmpJson);

}
}
// }
// }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/admin/edit-template/edit-template.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<div class="d-flex flex-justify-between py-1 px-4">
<div class="heading-2">{{'JSON_SCHEMA' | translate}}</div>
</div>
<advance-editor *ngIf="userJson" [jsonSchema]="userJson" (newItemEvent)="jsonSchemaData($event)"></advance-editor>
<advance-editor *ngIf="userJson" [jsonSchema]="userJson" (newItemEvent)="jsonSchemaData($event)" [schemaOsid]="schemaOsid"></advance-editor>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit b568a6b

Please sign in to comment.