Skip to content

Commit

Permalink
Merge pull request #38 from niscy-eudiw/RequestItem
Browse files Browse the repository at this point in the history
RequestItem struct
  • Loading branch information
phisakel authored Nov 19, 2024
2 parents 2f00a68 + c0cec28 commit 12f22d0
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift

name: Swift

on: [push]
on:
pull_request:
types: [opened, reopened]
push:
branches: ['main']
tags: [ v* ]

jobs:
build:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class MdocGattServer: @unchecked Sendable, ObservableObject {
}

@objc(CBPeripheralManagerDelegate)
class Delegate: NSObject, @preconcurrency CBPeripheralManagerDelegate {
class Delegate: NSObject, CBPeripheralManagerDelegate {
unowned var server: MdocGattServer

init(server: MdocGattServer) {
Expand Down Expand Up @@ -267,6 +267,7 @@ public class MdocGattServer: @unchecked Sendable, ObservableObject {
}
}
catch { errorToSend = error }
if let errorToSend { logger.error("Error preparing response: \(errorToSend.localizedDescription)") }
}
}

Expand Down
12 changes: 6 additions & 6 deletions Sources/MdocDataTransfer18013/MdocHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import SwiftCBOR
import Logging
import X509

public typealias RequestItems = [String: [String: [String]]]
public typealias RequestItems = [String: [String: [RequestItem]]]

/// Helper methods
public class MdocHelpers {
Expand Down Expand Up @@ -157,11 +157,11 @@ public class MdocHelpers {
guard let issuerNs = doc.issuerNameSpaces else { logger.error("Document does not contain issuer namespaces"); return nil }
var nsItemsToAdd = [NameSpace: [IssuerSignedItem]]()
var nsErrorsToAdd = [NameSpace: ErrorItems]()
var validReqItemsNsDict = [NameSpace: [String]]()
var validReqItemsNsDict = [NameSpace: [RequestItem]]()
// for each request namespace
let reqNamespaces = if haveSelectedItems { Array(selectedItems![reqDocIdOrDocType]!.keys)} else { Array(docReq!.itemsRequest.requestNameSpaces.nameSpaces.keys) }
for reqNamespace in reqNamespaces {
let reqElementIdentifiers = if haveSelectedItems { Array(selectedItems![reqDocIdOrDocType]![reqNamespace]!)} else { docReq!.itemsRequest.requestNameSpaces.nameSpaces[reqNamespace]!.elementIdentifiers }
let reqElementIdentifiers = if haveSelectedItems { Array(selectedItems![reqDocIdOrDocType]![reqNamespace]!).map(\.elementIdentifier) } else { docReq!.itemsRequest.requestNameSpaces.nameSpaces[reqNamespace]!.elementIdentifiers }
guard let items = issuerNs[reqNamespace] else {
nsErrorsToAdd[reqNamespace] = Dictionary(grouping: reqElementIdentifiers, by: {$0}).mapValues { _ in 0 }
continue
Expand All @@ -172,11 +172,11 @@ public class MdocHelpers {
var itemsToAdd = items.filter({ itemsReqSet.contains($0.elementIdentifier) })
if let selectedItems {
let selectedNsItems = selectedItems[reqDocIdOrDocType]?[reqNamespace] ?? []
itemsToAdd = itemsToAdd.filter({ selectedNsItems.contains($0.elementIdentifier) })
itemsToAdd = itemsToAdd.filter({ selectedNsItems.map(\.elementIdentifier).contains($0.elementIdentifier) })
}
if itemsToAdd.count > 0 {
nsItemsToAdd[reqNamespace] = itemsToAdd
validReqItemsNsDict[reqNamespace] = itemsToAdd.map(\.elementIdentifier)
validReqItemsNsDict[reqNamespace] = itemsToAdd.map { RequestItem(elementIdentifier: $0.elementIdentifier, intentToRetail: docReq?.itemsRequest.requestNameSpaces.nameSpaces[reqNamespace]?.dataElements[$0.elementIdentifier] ?? false, isOptional: false) }
}
let errorItemsSet = itemsReqSet.subtracting(itemsSet)
if errorItemsSet.count > 0 {
Expand All @@ -203,7 +203,7 @@ public class MdocHelpers {
} else {
docErrors.append([doc.issuerAuth.mso.docType: UInt64(0)])
}
errorReqItemsDocDict[doc.issuerAuth.mso.docType] = nsErrorsToAdd.mapValues { Array($0.keys) }
errorReqItemsDocDict[doc.issuerAuth.mso.docType] = nsErrorsToAdd.mapValues { $0.keys.map(RequestItem.init) }
} // end doc for
let documentErrors: [DocumentError]? = docErrors.count == 0 ? nil : docErrors.map(DocumentError.init(docErrors:))
let documentsToAdd = docFiltered.count == 0 ? nil : docFiltered
Expand Down
33 changes: 33 additions & 0 deletions Sources/MdocDataTransfer18013/RequestItem.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright (c) 2023 European Commission

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 Foundation

public struct RequestItem: Sendable {
public init(elementIdentifier: String, intentToRetail: Bool, isOptional: Bool) {
self.elementIdentifier = elementIdentifier
self.intentToRetail = intentToRetail
self.isOptional = isOptional
}
public init(elementIdentifier: String) {
self.elementIdentifier = elementIdentifier
self.intentToRetail = false
self.isOptional = false
}

let elementIdentifier: String
let intentToRetail: Bool
let isOptional: Bool
}

0 comments on commit 12f22d0

Please sign in to comment.