Skip to content

Commit

Permalink
Business Rules version (#94)
Browse files Browse the repository at this point in the history
* added downloading rules, valueSets, country list

* fixed crash on loading rules

* wallet app with busines rules

* added hash value check for downloaded data

* added localization for wallet
added correct texts
added new resources

* fixed issues

* Business rules version

Co-authored-by: Alexandr Chernyy <[email protected]>
  • Loading branch information
alexchornyi and pingus-nikalex authored Jul 20, 2021
1 parent cdae092 commit 8920417
Show file tree
Hide file tree
Showing 36 changed files with 2,303 additions and 28 deletions.
9 changes: 9 additions & 0 deletions context.jsonc → Context/Release/context.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
"lKdU1EbQubxyDDm2q3N8KclZ2C94Num3xXjG0pk+3eI=",
"r/mIkG3eEpVdm+u/ko/cwxzOMo1bk4TyHIlByibiA5E="
]
},
"countryList": {
"url": "https://dgca-businessrule-service.cfapps.eu10.hana.ondemand.com/countrylist"
},
"rules": {
"url": "https://dgca-businessrule-service.cfapps.eu10.hana.ondemand.com/rules"
},
"valuesets": {
"url": "https://dgca-businessrule-service.cfapps.eu10.hana.ondemand.com/valuesets"
}
}
},
Expand Down
39 changes: 39 additions & 0 deletions Context/Test/context.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
// Origin in ISO alpha 2 code:
"origin": "DE",
"versions": {
"default": {
// catch-all for normal versions
"privacyUrl": "https://publications.europa.eu/en/web/about-us/legal-notices/eu-mobile-apps",
"context": {
"url": "https://dgca-issuance-web-eu-acc.cfapps.eu10.hana.ondemand.com/dgca-issuance-service/context",
"pubKeys": [
"lKdU1EbQubxyDDm2q3N8KclZ2C94Num3xXjG0pk+3eI=",
"r/mIkG3eEpVdm+u/ko/cwxzOMo1bk4TyHIlByibiA5E="
]
},
"endpoints": {
"claim": {
"url": "https://issuance-dgca-test.cfapps.eu10.hana.ondemand.com/dgca-issuance-service/dgci/wallet/claim",
"pubKeys": [
"lKdU1EbQubxyDDm2q3N8KclZ2C94Num3xXjG0pk+3eI=",
"r/mIkG3eEpVdm+u/ko/cwxzOMo1bk4TyHIlByibiA5E="
]
},
"countryList": {
"url": "https://dgca-businessrule-service.cfapps.eu10.hana.ondemand.com/countrylist"
},
"rules": {
"url": "https://dgca-businessrule-service.cfapps.eu10.hana.ondemand.com/rules"
},
"valuesets": {
"url": "https://dgca-businessrule-service.cfapps.eu10.hana.ondemand.com/valuesets"
}
}
},
"0.1.0": {
// Example for a version that is insecure and shouldn't start.
"outdated": true
}
}
}
239 changes: 226 additions & 13 deletions DGCAWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,21 @@
"version": "1.8.0"
}
},
{
"package": "CertLogic",
"repositoryURL": "https://github.com/eu-digital-green-certificates/dgc-certlogic-ios.git",
"state": {
"branch": "main",
"revision": "8b7f86a2aed4f2c60dd2c7c4f28eb129d9fe379d",
"version": null
}
},
{
"package": "SwiftDGC",
"repositoryURL": "https://github.com/eu-digital-green-certificates/dgca-app-core-ios",
"state": {
"branch": "main",
"revision": "96a5bf0ec02fc56bb5c59a4fd579f381f5da9a55",
"branch": "bugfix/hc1",
"revision": "629f1a31adfbf62bd37a165558ce1a37492c05a2",
"version": null
}
},
Expand All @@ -37,6 +46,15 @@
"version": "2.4.0"
}
},
{
"package": "jsonlogic",
"repositoryURL": "https://github.com/eu-digital-green-certificates/json-logic-swift.git",
"state": {
"branch": null,
"revision": "8dc339147b27ae633a1857503ed8d091c7935d0d",
"version": "1.1.5"
}
},
{
"package": "JSONSchema",
"repositoryURL": "https://github.com/eu-digital-green-certificates/JSONSchema.swift",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
//
/*-
* ---license-start
* eu-digital-green-certificates / dgca-wallet-app-ios
* ---
* Copyright (C) 2021 T-Systems International GmbH and all other contributors
* ---
* 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.
* ---license-end
*/
//
// CellWithDateAndCountryTVC.swift
// DGCAWallet
//
// Created by Alexandr Chernyy on 08.07.2021.
//


import UIKit
import SwiftDGC

public typealias OnDateChangedHandler = (Date) -> Void
public typealias OnCountryChangedHandler = (String?) -> Void

class CellWithDateAndCountryTVC: UITableViewCell {
@IBOutlet weak var destinationLabel: UILabel!
@IBOutlet weak var countryPicker: UIPickerView!
@IBOutlet weak var dateLabel: UILabel!
@IBOutlet weak var datePicker: UIDatePicker!
private var countryItems: [CountryModel] = []
var dataHandler: OnDateChangedHandler?
var countryHandler: OnCountryChangedHandler?
// Selected country code
private var selectedCounty: CountryModel? {
set {
let userDefaults = UserDefaults.standard
do {
try userDefaults.setObject(newValue, forKey: Constants.userDefaultsCountryKey)
} catch {
print(error.localizedDescription)
}
}
get {
let userDefaults = UserDefaults.standard
do {
let selected = try userDefaults.getObject(forKey: Constants.userDefaultsCountryKey, castTo: CountryModel.self)
return selected
} catch {
print(error.localizedDescription)
return nil
}
}
}
func setupView() {
destinationLabel.text = l10n("destination_country")
dateLabel.text = l10n("destination_date")
countryPicker.delegate = self
countryPicker.dataSource = self
datePicker.minimumDate = Date()
if #available(iOS 13.4, *) {
datePicker.preferredDatePickerStyle = .wheels
} else {
// Fallback on earlier versions
}
datePicker.addTarget(self, action: #selector(dateChanged(_:)), for: .valueChanged)
GatewayConnection.countryList { countryList in
DispatchQueue.main.async {
self.setListOfRuleCounties(list: countryList)
}
}
}
}

extension CellWithDateAndCountryTVC {
@objc func dateChanged(_ sender: UIDatePicker) {
dataHandler?(sender.date)
}
}

extension CellWithDateAndCountryTVC: UIPickerViewDataSource, UIPickerViewDelegate {
public func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
public func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
if countryItems.count == 0 { return 1 }
return countryItems.count
}
public func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
if countryItems.count == 0 { return l10n("scaner.no.countrys") }
return countryItems[row].name
}
public func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
self.selectedCounty = countryItems[row]
countryHandler?(self.selectedCounty?.code)
}
}

extension CellWithDateAndCountryTVC {
public func setListOfRuleCounties(list: [CountryModel]) {
self.countryItems = list
self.countryPicker.reloadAllComponents()
guard self.countryItems.count > 0 else { return }
if let selected = self.selectedCounty,
let indexOfCountry = self.countryItems.firstIndex(where: {$0.code == selected.code}) {
countryPicker.selectRow(indexOfCountry, inComponent: 0, animated: false)
countryHandler?(selected.code)
} else {
self.selectedCounty = self.countryItems.first
countryPicker.selectRow(0, inComponent: 0, animated: false)
countryHandler?(self.selectedCounty?.code)
}
}
public func getSelectedCountryCode() -> String? {
return self.selectedCounty?.code
}
}

extension CellWithDateAndCountryTVC {
private enum Constants {
static let userDefaultsCountryKey = "UDWalletCountryKey"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="CellWithDateAndCountryTVC" rowHeight="237" id="KGk-i7-Jjw" customClass="CellWithDateAndCountryTVC" customModule="DGCAWallet" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="310" height="237"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" ambiguous="YES" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<rect key="frame" x="0.0" y="0.0" width="310" height="237"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Your destination country" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="IFu-HS-AtD">
<rect key="frame" x="16" y="8" width="278" height="20"/>
<constraints>
<constraint firstAttribute="height" constant="20" id="S2V-MV-EFz"/>
</constraints>
<fontDescription key="fontDescription" type="boldSystem" pointSize="14"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<pickerView contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="b4h-nK-Yro">
<rect key="frame" x="10" y="36" width="290" height="100"/>
<constraints>
<constraint firstAttribute="height" constant="100" id="EN9-0I-zDl"/>
</constraints>
</pickerView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Check the date" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4cL-ba-yHg">
<rect key="frame" x="16" y="144" width="278" height="20"/>
<constraints>
<constraint firstAttribute="height" constant="20" id="IVw-iO-pXH"/>
</constraints>
<fontDescription key="fontDescription" type="boldSystem" pointSize="14"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<datePicker contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" datePickerMode="date" translatesAutoresizingMaskIntoConstraints="NO" id="Yx0-Qk-PSp">
<rect key="frame" x="10" y="172" width="290" height="50"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="24x-X5-fzE"/>
</constraints>
<date key="maximumDate" timeIntervalSinceReferenceDate="1167562800">
<!--2037-12-31 11:00:00 +0000-->
</date>
</datePicker>
</subviews>
<constraints>
<constraint firstItem="b4h-nK-Yro" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="10" id="6kA-as-g1g"/>
<constraint firstAttribute="trailing" secondItem="IFu-HS-AtD" secondAttribute="trailing" constant="16" id="BWd-7V-bV8"/>
<constraint firstItem="Yx0-Qk-PSp" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leadingMargin" constant="-6" id="Ibl-hv-DrN"/>
<constraint firstItem="4cL-ba-yHg" firstAttribute="top" secondItem="b4h-nK-Yro" secondAttribute="bottom" constant="8" id="KhZ-2v-iGu"/>
<constraint firstItem="IFu-HS-AtD" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="8" id="LCJ-rI-cZo"/>
<constraint firstItem="Yx0-Qk-PSp" firstAttribute="trailing" secondItem="H2p-sc-9uM" secondAttribute="trailingMargin" constant="6" id="Lic-TY-6qD"/>
<constraint firstItem="Yx0-Qk-PSp" firstAttribute="top" secondItem="4cL-ba-yHg" secondAttribute="bottom" constant="8" id="NiU-PC-jQN"/>
<constraint firstItem="4cL-ba-yHg" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leadingMargin" id="Pak-4a-jYL"/>
<constraint firstItem="IFu-HS-AtD" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="16" id="Zrd-gK-t17"/>
<constraint firstItem="4cL-ba-yHg" firstAttribute="trailing" secondItem="H2p-sc-9uM" secondAttribute="trailingMargin" id="jbz-Qd-pIq"/>
<constraint firstItem="Yx0-Qk-PSp" firstAttribute="bottom" secondItem="H2p-sc-9uM" secondAttribute="bottomMargin" id="jkO-RJ-Kzd"/>
<constraint firstItem="b4h-nK-Yro" firstAttribute="top" secondItem="IFu-HS-AtD" secondAttribute="bottom" constant="8" id="oSI-vs-KXn"/>
<constraint firstAttribute="trailing" secondItem="b4h-nK-Yro" secondAttribute="trailing" constant="10" id="z0Z-Le-MwH"/>
</constraints>
</tableViewCellContentView>
<viewLayoutGuide key="safeArea" id="njF-e1-oar"/>
<connections>
<outlet property="countryPicker" destination="b4h-nK-Yro" id="R5x-qs-iNc"/>
<outlet property="dateLabel" destination="4cL-ba-yHg" id="zNz-Pa-fX0"/>
<outlet property="datePicker" destination="Yx0-Qk-PSp" id="UJd-xv-Xta"/>
<outlet property="destinationLabel" destination="IFu-HS-AtD" id="L8S-1x-09r"/>
</connections>
<point key="canvasLocation" x="-24.637681159420293" y="189.17410714285714"/>
</tableViewCell>
</objects>
</document>
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
/*-
* ---license-start
* eu-digital-green-certificates / dgca-wallet-app-ios
* ---
* Copyright (C) 2021 T-Systems International GmbH and all other contributors
* ---
* 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.
* ---license-end
*/
//
// CellWithTitleAndDescriptionTVC.swift
// DGCAWallet
//
// Created by Alexandr Chernyy on 08.07.2021.
//


import UIKit

class CellWithTitleAndDescriptionTVC: UITableViewCell {
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var descriptionLabel: UILabel!

private weak var cellModel: ValidityCellModel? {
didSet {
self.setupView()
}
}

override func awakeFromNib() {
super.awakeFromNib()
setInitialStrings()
}

override func prepareForReuse() {
super.prepareForReuse()
setInitialStrings()
}

func setupCell(with model: ValidityCellModel) {
self.cellModel = model
}

private func setInitialStrings() {
titleLabel.text = ""
descriptionLabel.text = ""
}

private func setupView() {
guard let cellModel = cellModel else {
setInitialStrings()
return
}
titleLabel.text = cellModel.title
descriptionLabel.text = cellModel.description
if cellModel.needChangeTitleFont {
titleLabel.font = UIFont.boldSystemFont(ofSize: 24)
} else {
titleLabel.font = UIFont.boldSystemFont(ofSize: 14)
}
}

}
Loading

0 comments on commit 8920417

Please sign in to comment.