Created basic golang server for display results

draft_specifications
meerkat 2021-11-21 21:36:20 +11:00
parent c6a519c6b6
commit f9566efe53
30 changed files with 6438 additions and 344 deletions

View File

@ -1,7 +1,8 @@
. ..\..\..\source\powershell\MartiLQ.ps1
. ..\..\..\source\powershell\MartiLQItem.ps1
. ..\..\..\source\powershell\Compress-MartiLQ.ps1
. ..\..\..\source\powershell\MartiLQConfiguration.ps1
. ..\..\..\source\powershell\MartiLQResource.ps1
. ..\..\..\source\powershell\MartiLQAttribute.ps1
function PullFtpFile {

View File

@ -1,7 +1,8 @@
. ..\..\..\source\powershell\MartiLQ.ps1
. ..\..\..\source\powershell\MartiLQItem.ps1
. ..\..\..\source\powershell\Compress-MartiLQ.ps1
. ..\..\..\source\powershell\MartiLQConfiguration.ps1
. ..\..\..\source\powershell\MartiLQResource.ps1
. ..\..\..\source\powershell\MartiLQAttribute.ps1
function PullFtpFile {

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,96 @@
{
"content-type": "application/vnd.martilq.json",
"title": "Conversion from CKAN",
"uid": "f2b7c2c1-f4ef-4ae9-aba5-45c19e4d3038",
"description": "###Update November 2019 - additional fields ###\r\n\r\nFrom 21 November 2019, the dataset will be updated to include 7 new fields (see help file for details)\r\n\r\nThese fields are included in conjunction with the professional standards reforms for financial advisers. More information can be found on the ASIC website https://asic.gov.au/regulatory-resources/financial-services/professional-standards-for-financial-advisers-reforms/.\r\n\r\n__Note:__ For most advisers the new fields will be unpopulated on 21 November 2019. As advisers provide this data to ASIC it will appear in the dataset.\r\n\r\n***\r\n\r\n###Dataset summary###\r\n\r\nASIC is Australias corporate, markets and financial services regulator. ASIC contributes to Australias economic reputation and wellbeing by ensuring that Australias financial markets are fair and transparent, supported by confident and informed investors and consumers. \r\n \r\nAustralian Financial Services Licensees are required to keep the details of their financial advisers up to date on ASIC's Financial Advisers Register. Information contained in the register is made available to the public to search via ASIC's Moneysmart website. \r\n\r\nSelect data from the Financial Advisers Register will be uploaded each week to www.data.gov.au. The data made available will be a snapshot of the register at a point in time. Legislation prescribes the type of information ASIC is allowed to disclose to the public. \r\n\r\nThe information included in the downloadable dataset is: \r\n\r\n* Adviser name\r\n* Adviser number\r\n* Adviser role\r\n* Adviser sub type\r\n* Adviser role status\r\n* Adviser ABN\r\n* Year first provided advice \r\n* Licence name\r\n* Licence number\r\n* Licence ABN\r\n* Licence controlled by\r\n* Adviser start date\r\n* Adviser end date\r\n* Adviser CPD failure year\r\n* Adviser principal business address suburb\r\n* Adviser principal business address State/Territory\r\n* Adviser principal business address postcode\r\n* Adviser principal business address Country\r\n* Appointing representative name\r\n* Appointing representative number\r\n* Appointing representative ABN\r\n* Disciplinary action start date\r\n* Disciplinary action end date\r\n* Disciplinary action type\r\n* Product authorisations (for a full list see the Financial Adviser Register Help File)\r\n* Qualifications and Training\r\n* FASEA approved qualifications\r\n* Memberships\r\n* Further restrictions\r\n\r\nAdditional information about financial advisers can be found via [ASIC's website] (http://www.asic.gov.au/ \"ASIC's website\"). Accessing some information may attract a fee. \r\n\r\nMore information about searching [ASIC's registers] (http://www.asic.gov.au/online-services/search-asics-registers/ \"ASIC's registers\"). ",
"issued": "2021-11-06T13:48:28",
"modified": "2021-11-06T13:48:28",
"expires": "",
"tags": [
"document",
"marti"
],
"publisher": "VCOFF\\meerkat",
"contactPoint": "Access.Request@asic.gov.au",
"accessLevel": "Confidential",
"rights": "Restricted",
"license": "cc-by",
"state": "active",
"batch": 1.0,
"describedBy": "",
"landingPage": "",
"theme": "",
"resources": [
{
"title": "Financial Advisers Dataset - Help File",
"uid": "b4fc36ca-b9d5-4ad4-9631-c914367ea302",
"documentName": "financial-advisers-register-help-file.pdf",
"issuedDate": "2015-05-19T05:10:05.120187",
"modified": "2021-03-29T02:23:10.146935",
"state": "active",
"author": "Australian Securities and Investments Commission (ASIC)",
"length": 741345,
"hash": {
"algo": "SHA256",
"value": "22552e688cf87ff1edcaf000daec307c",
"signed": false
},
"description": "Help File as at 29/03/2021",
"url": "https://data.gov.au/data/dataset/f2b7c2c1-f4ef-4ae9-aba5-45c19e4d3038/resource/b4fc36ca-b9d5-4ad4-9631-c914367ea302/download/financial-advisers-register-help-file.pdf",
"version": "1.1.0",
"format": "PDF",
"compression": "",
"encryption": ""
},
{
"title": "Financial Advisers Dataset - Current",
"uid": "691ff9ed-b601-481d-8283-88127dbbc869",
"documentName": "financial_advisers_202109.zip",
"issuedDate": "2015-07-14T05:18:49.260369",
"modified": "2021-09-08T20:42:41.180925",
"state": "active",
"author": "Australian Securities and Investments Commission (ASIC)",
"length": 4724626,
"hash": {
"algo": "SHA256",
"value": "5708dfd23d7a089d78da03932e4f8871",
"signed": false
},
"description": "Financial Advisers Dataset extract as at 09/09/2021 06:42",
"url": "https://data.gov.au/data/dataset/f2b7c2c1-f4ef-4ae9-aba5-45c19e4d3038/resource/691ff9ed-b601-481d-8283-88127dbbc869/download/financial_advisers_202109.zip",
"version": "1.1.0",
"format": "CSV",
"compression": "",
"encryption": ""
},
{
"title": "Financial Advisers Dataset - Current",
"uid": "2156cb99-3358-4847-8b5b-fcd2f0d3c4e2",
"documentName": "financial_advisers_202109.xlsx",
"issuedDate": "2016-11-02T11:54:38.840025",
"modified": "2021-09-08T20:42:43.173322",
"state": "active",
"author": "Australian Securities and Investments Commission (ASIC)",
"length": 9518613,
"hash": {
"algo": "SHA256",
"value": "",
"signed": false
},
"description": "Financial Advisers Dataset extract as at 09/09/2021 06:42",
"url": "https://data.gov.au/data/dataset/f2b7c2c1-f4ef-4ae9-aba5-45c19e4d3038/resource/2156cb99-3358-4847-8b5b-fcd2f0d3c4e2/download/financial_advisers_202109.xlsx",
"version": "1.1.0",
"format": "XLSX",
"compression": "",
"encryption": ""
}
],
"custom": [
{
"extension": "software",
"softwareName": "MartiReference",
"author": "Meerkat@merebox.com",
"version": "0.0.1"
}
]
}

View File

@ -0,0 +1,71 @@
package main
import (
"flag"
"log"
"net/http"
"strings"
"path/filepath"
"os"
)
func main() {
port := flag.String("p", "8080", "Http listen port")
directory := flag.String("d", "static", "Static directory content")
docsDirectory := flag.String("docs", "", "Docs directory content")
flag.Parse()
http.HandleFunc("/data/", func( res http.ResponseWriter, req *http.Request ) {
//log.Printf("Data file %s \n", req.URL.Path)
http.ServeFile(res, req, req.URL.Path[1:]);
})
http.HandleFunc("/docs/", func( res http.ResponseWriter, req *http.Request ) {
if (*docsDirectory == "") {
temp := "../../.."
docsDirectory = &temp
}
//log.Printf("Docs file %s \n", req.URL.Path)
localPath := filepath.FromSlash(*docsDirectory+req.URL.Path)
f, err := os.Open(localPath)
if err != nil {
http.ServeFile(res, req, filepath.FromSlash(*directory + "/404.html"));
} else {
s, err := f.Stat()
if err != nil || s.IsDir() {
http.ServeFile(res, req, filepath.FromSlash(*directory + "/404.html"));
} else {
http.ServeFile(res, req, localPath);
}
}
})
fileServer := http.FileServer(FileSystem{http.Dir(*directory)})
http.Handle("/", fileServer)
log.Printf("Serving \"%s\" on HTTP port: %s\n", *directory, *port)
log.Fatal(http.ListenAndServe(":"+*port, nil))
}
type FileSystem struct {
fs http.FileSystem
}
func (fs FileSystem) Open(path string) (http.File, error) {
f, err := fs.fs.Open(path)
if err != nil {
return nil, err
}
s, err := f.Stat()
//log.Printf("File %s \n", path)
if s.IsDir() {
index := strings.TrimSuffix(path, "/") + "/index.html"
if _, err := fs.fs.Open(index); err != nil {
return nil, err
}
}
return f, nil
}

View File

@ -0,0 +1,10 @@
<html>
<body>
<div role="main">
<div class="section">
<h1 id="404-page-not-found">404</h1>
<p><strong>Page not found</strong></p>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="408" fill="#fff"><path d="M106.342 0c-29.214 0-50.827 25.58-49.86 53.32.927 26.647-.278 61.165-8.966 89.31C38.802 170.862 24.07 188.707 0 191v26c24.069 2.293 38.802 20.138 47.516 48.37 8.688 28.145 9.893 62.663 8.965 89.311C55.515 382.42 77.128 408 106.342 408h299.353c29.214 0 50.827-25.58 49.861-53.319-.928-26.648.277-61.166 8.964-89.311 8.715-28.232 23.411-46.077 47.48-48.37v-26c-24.069-2.293-38.765-20.138-47.48-48.37-8.687-28.145-9.892-62.663-8.964-89.31C456.522 25.58 434.909 0 405.695 0H106.342zm236.559 251.102c0 38.197-28.501 61.355-75.798 61.355h-87.202a2 2 0 01-2-2v-213a2 2 0 012-2h86.74c39.439 0 65.322 21.354 65.322 54.138 0 23.008-17.409 43.61-39.594 47.219v1.203c30.196 3.309 50.532 24.212 50.532 53.085zm-84.58-128.125h-45.91v64.814h38.669c29.888 0 46.373-12.03 46.373-33.535 0-20.151-14.174-31.279-39.132-31.279zm-45.91 90.53v71.431h47.605c31.12 0 47.605-12.482 47.605-35.941 0-23.46-16.947-35.49-49.608-35.49h-45.602z"/></svg>

After

Width:  |  Height:  |  Size: 1007 B

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="408"><defs><linearGradient id="bs-logo-a" x1="76.079" x2="523.48" y1="10.798" y2="365.945" gradientUnits="userSpaceOnUse"><stop stop-color="#9013fe"/><stop offset="1" stop-color="#6610f2"/></linearGradient><linearGradient id="bs-logo-b" x1="193.508" x2="293.514" y1="109.74" y2="278.872" gradientUnits="userSpaceOnUse"><stop stop-color="#fff"/><stop offset="1" stop-color="#f1e5fc"/></linearGradient><filter xmlns="http://www.w3.org/2000/svg" id="bs-logo-c" width="197" height="249" x="161.901" y="83.457" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feColorMatrix in="SourceAlpha" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"/><feOffset dy="4"/><feGaussianBlur stdDeviation="8"/><feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.15 0"/><feBlend in2="BackgroundImageFix" result="effect1_dropShadow"/><feBlend in="SourceGraphic" in2="effect1_dropShadow" result="shape"/></filter></defs><path fill="url(#bs-logo-a)" d="M56.481 53.32C55.515 25.58 77.128 0 106.342 0h299.353c29.214 0 50.827 25.58 49.861 53.32-.928 26.647.277 61.165 8.964 89.31 8.715 28.232 23.411 46.077 47.48 48.37v26c-24.069 2.293-38.765 20.138-47.48 48.37-8.687 28.145-9.892 62.663-8.964 89.311.966 27.739-20.647 53.319-49.861 53.319H106.342c-29.214 0-50.827-25.58-49.86-53.319.927-26.648-.278-61.166-8.966-89.311C38.802 237.138 24.07 219.293 0 217v-26c24.069-2.293 38.802-20.138 47.516-48.37 8.688-28.145 9.893-62.663 8.965-89.31z"/><path fill="url(#bs-logo-b)" filter="url(#bs-logo-c)" stroke="#fff" d="M267.103 312.457c47.297 0 75.798-23.158 75.798-61.355 0-28.873-20.336-49.776-50.532-53.085v-1.203c22.185-3.609 39.594-24.211 39.594-47.219 0-32.783-25.882-54.138-65.322-54.138h-88.74v217h89.202zm-54.692-189.48h45.911c24.958 0 39.131 11.128 39.131 31.279 0 21.505-16.484 33.535-46.372 33.535h-38.67v-64.814zm0 161.961v-71.431h45.602c32.661 0 49.608 12.03 49.608 35.49 0 23.459-16.484 35.941-47.605 35.941h-47.605z"/></svg>

After

Width:  |  Height:  |  Size: 2.0 KiB

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,100 @@
body {
font-size: .875rem;
}
.feather {
width: 16px;
height: 16px;
vertical-align: text-bottom;
}
/*
* Sidebar
*/
.sidebar {
position: fixed;
top: 0;
/* rtl:raw:
right: 0;
*/
bottom: 0;
/* rtl:remove */
left: 0;
z-index: 100; /* Behind the navbar */
padding: 48px 0 0; /* Height of navbar */
box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);
}
@media (max-width: 767.98px) {
.sidebar {
top: 5rem;
}
}
.sidebar-sticky {
position: relative;
top: 0;
height: calc(100vh - 48px);
padding-top: .5rem;
overflow-x: hidden;
overflow-y: auto; /* Scrollable contents if viewport is shorter than content. */
}
.sidebar .nav-link {
font-weight: 500;
color: #333;
}
.sidebar .nav-link .feather {
margin-right: 4px;
color: #727272;
}
.sidebar .nav-link.active {
color: #2470dc;
}
.sidebar .nav-link:hover .feather,
.sidebar .nav-link.active .feather {
color: inherit;
}
.sidebar-heading {
font-size: .75rem;
text-transform: uppercase;
}
/*
* Navbar
*/
.navbar-brand {
padding-top: .75rem;
padding-bottom: .75rem;
font-size: 1rem;
background-color: rgba(0, 0, 0, .25);
box-shadow: inset -1px 0 0 rgba(0, 0, 0, .25);
}
.navbar .navbar-toggler {
top: .25rem;
right: 1rem;
}
.navbar .form-control {
padding: .75rem 1rem;
border-width: 0;
border-radius: 0;
}
.form-control-dark {
color: #fff;
background-color: rgba(255, 255, 255, .1);
border-color: rgba(255, 255, 255, .1);
}
.form-control-dark:focus {
border-color: transparent;
box-shadow: 0 0 0 3px rgba(255, 255, 255, .25);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

View File

@ -0,0 +1,66 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
<meta name="generator" content="Hugo 0.88.1">
<title>MartiLQ Dashboard</title>
<!-- Bootstrap core CSS -->
<link href="assets/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
.bd-placeholder-img {
font-size: 1.125rem;
text-anchor: middle;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
@media (min-width: 768px) {
.bd-placeholder-img-lg {
font-size: 3.5rem;
}
}
</style>
<!-- Custom styles for this template -->
<link href="css/dashboard.css" rel="stylesheet">
</head>
<body>
<header class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow">
<a class="navbar-brand col-md-3 col-lg-2 me-0 px-3" href="#">Meerkat Manor</a>
<input class="form-control form-control-dark w-100" type="text" placeholder="Load definition" aria-label="Load" id="loaddefinition">
<button class="w-50 btn btn-primary" type="submit" id="loadBtn">Load</button>
</header>
<div class="container-fluid">
<div class="row">
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
<h2>MartiLQ definition</h2>
<div class="table-responsive">
<div class="output"></div>
</div>
</main>
</div>
</div>
<footer class="bg-dark flex-md-nowrap p-0 shadow">
<div class="row">
<a target="_blank" href="https://icons8.com/icon/64141/internet">Internet</a> icon by <a target="_blank" href="https://icons8.com">Icons8</a>
</div>
</footer>
<script src="assets/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons@4.28.0/dist/feather.min.js" integrity="sha384-uO3SXW5IuS1ZpFPKugNNWqTZRRglnUJK6UAZ/gxOX80nxEkN9NcGZTftn6RzhGWE" crossorigin="anonymous"></script><script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js" integrity="sha384-zNy6FEbO50N+Cg5wap8IKA4M/ZnLJgzc6w2NqACZaK0u0FXfOWRRJOnQtpZun8ha" crossorigin="anonymous"></script>
<script src="js/app.js"></script>
</body>
</html>

View File

@ -0,0 +1,103 @@
"use strict";
const output = document.querySelector(".output");
var localJsonFile = "data/marti_test_asic.json";
var btn = document.getElementById("loadBtn");
btn.onclick = dataLoadFunction;
function dataLoadFunction() {
var loadDef = document.getElementById("loaddefinition")
fetchData("data/"+loadDef.value);
}
window.addEventListener("DOMContentLoaded", () => {
var urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('martilq')) {
var loadDef = urlParams.get('martilq');
fetchData("data/"+ loadDef);
var ld = document.getElementById("loaddefinition")
ld.value = loadDef
} else {
output.textContent = "Please supply a MartiLQ definition to load, such as \"marti_test_asic.json\"";
}
});
function fetchData(dataFile) {
output.textContent = "Loading....";
fetch(dataFile)
.then((response) => response.json())
.then((data) => {
output.innerHTML = "";
var hdr = itemHeader(data)
output.append(hdr);
const br = document.createElement("br");
output.append(br);
const tble = document.createElement("table");
tble.classList.add("table");
tble.classList.add("table-striped");
tble.classList.add("table-sm");
var thd = document.createElement("thead");
var th = document.createElement("tr");
//scope="col"
th.innerHTML = "<th>Title</th><th>Document</th><th>Size</th><th>Issued</th><th>Modified</th><th>Expires</th><th>State</th><th>Version</th>";
thd.append(th);
tble.append(thd);
var tby = document.createElement("tbody");
data.resources.forEach((el) => {
//console.log(el);
jsonList(tby, el);
});
tble.append(tby);
output.append(tble);
});
}
function jsonList(tble, item) {
const tr = document.createElement("tr");
tr.innerHTML = itemRow(item);
tble.append(tr);
}
function itemHeader(item) {
const hdr = document.createElement("table");
hdr.classList.add("table");
hdr.classList.add("table-striped");
hdr.classList.add("table-sm");
var describe = item.description.replace(/\r\n/g, "<br>");
var rows = `<tr><th>Title</th><td>${item.title}</td></tr>`;
rows = rows+ `<tr><th>UID</th><td>${item.uid}</td></tr>`;
rows = rows+ `<tr><th>Description</th><td>${describe}</td></tr>`;
rows = rows+ `<tr><th>Issued</th><td>${item.issued}</td></tr>`;
rows = rows+ `<tr><th>Modified</th><td>${item.modified}</td></tr>`;
rows = rows+ `<tr><th>Access Level</th><td>${item.accessLevel}</td></tr>`;
rows = rows+ `<tr><th>Rights</th><td>${item.rights}</td></tr>`;
hdr.innerHTML = rows;
return hdr
}
function itemRow(item) {
var row = `<td>${item.title}</td>`;
row = row + `<td><a href="${item.url}">${item.documentName}</a></td>`;
row = row + `<td>${item.length}</td>`;
row = row + `<td>${item.issuedDate}</td>`;
row = row + `<td>${item.modified}</td>`;
row = row + `<td>${item.expires}</td>`;
row = row + `<td>${item.state}</td>`;
row = row + `<td>${item.version}</td>`;
return row
}

View File

@ -1,153 +0,0 @@
function Compare-MartiResource {
Param(
[Parameter(Mandatory)][String] $DataSource,
[Parameter(Mandatory)][PSCustomObject] $Resource,
[String] $LogPath
)
$script:LogPathName = $LogPath
Write-Debug "Parameter: LogPath Value: $LogPath "
Open-Log
Write-Log "Function 'Compare-MartiResource' parameters follow"
Write-Log ""
if ($null -eq $Resource) {
$Global:MartiErrorId = "MRI2201"
$message = "No resource definition supplied"
Write-Log ($message + " " + $Global:MartiErrorId)
Close-Log
throw $message
}
if ($null -eq $DataSource -or $DataSource -eq "") {
$Global:MartiErrorId = "MRI2202"
$message = "No document supplied"
Write-Log ($message + " " + $Global:MartiErrorId)
Close-Log
throw $message
}
if ($DataSource.Length -le 1000) {
# Check if the name is a file
if (Test-Path -Path $DataSource) {
$inputData = Get-Content -Path $DataSource -Raw
Write-Host "Loading file $DataSource"
} else {
$inputData = $DataSource
}
} else {
$inputData = $DataSource
}
$formatProcessed = $false
[System.Collections.ArrayList]$lerror = @()
if ($Resource.format -eq "CSV") {
$formatProcessed = $true
$data = $inputData | ConvertFrom-Csv -Delim ','
$columns = ($data | get-member -type NoteProperty).count
$rows = @($data).count
$Resource.attributes | ForEach-Object {
if ($_.category -eq "dataset" -and $_.name -eq "records" -and $_.function -eq "count" -and $_.comparison -eq "EQ") {
if ($_.value -ne $rows) {
$oError = [PSCustomObject]@{
id = "MRI2203"
message = "Row count does not match"
found = "$rows"
expected = "$($_.value)"
}
$lerror += $oError
}
}
if ($_.category -eq "dataset" -and $_.name -eq "columns" -and $_.function -eq "count" -and $_.comparison -eq "EQ") {
if ($_.value -ne $columns) {
$oError = [PSCustomObject]@{
id = "MRI2204"
message = "Column count does not match"
found = "$columns"
expected = "$($_.value)"
}
$lerror += $oError
}
}
}
}
if ($Resource.format -eq "JSON") {
$formatProcessed = $true
$data = $inputData | ConvertFrom-Json
$rows = @($data.data.monitor).count
$item = $data.data.monitor[0]
$columns = ($item | get-member -type NoteProperty).count
$Resource.attributes | ForEach-Object {
if ($_.category -eq "dataset" -and $_.name -eq "records" -and $_.function -eq "count" -and $_.comparison -eq "EQ") {
if ($_.value -ne $rows) {
$oError = [PSCustomObject]@{
id = "MRI2203"
message = "Row count does not match"
found = "$rows"
expected = "$($_.value)"
}
$lerror += $oError
}
}
if ($_.category -eq "dataset" -and $_.name -eq "columns" -and $_.function -eq "count" -and $_.comparison -eq "EQ") {
if ($_.value -ne $columns) {
$oError = [PSCustomObject]@{
id = "MRI2204"
message = "Column count does not match"
found = "$columns"
expected = "$($_.value)"
}
$lerror += $oError
}
}
}
}
if (!$formatProcessed) {
$Global:MartiErrorId = "MRI2203"
$message = "Data format not supported"
Write-Log ($message + " " + $Global:MartiErrorId)
Close-Log
throw $message
}
$status = "OK"
if ($lerror.Count -gt 0) {
$status = "ERROR"
}
$oResult = [PSCustomObject]@{
status = $status
errors = $lerror
}
Close-Log
return $oResult
}

View File

@ -1,58 +0,0 @@
function Compress-MartiLQ
{
Param(
[Parameter(Mandatory)][String] $SourceFolder,
[Parameter(Mandatory)][String] $ArchiveFile,
[String] $Filter ="*",
[switch] $ExcludeHash,
[String] $LogPath
)
$script:LogPathName = $LogPath
Write-Debug "Parameter: LogPath Value: $LogPath "
Open-Log
Write-Log "Function 'Compress-MartiLQ' parameters follow"
Write-Log "Parameter: SourceFolder Value: $SourceFolder "
Write-Log "Parameter: ArchiveFile Value: $ArchiveFile "
Write-Log "Parameter: Filter Value: $Filter "
Write-Log ""
$marti_mri = $global:default_metaFile
$oMarti = New-MartiDefinition -SourceFolder $SourceFolder -Filter $Filter -LogPath $LogPath
$oMarti.description = "Sample execution"
$fullMetadatName = Join-Path -Path (Split-Path -Path $ArchiveFile -Parent) -ChildPath $marti_mri
$x = ConvertTo-Json -InputObject $oMarti
Add-Content -Path $fullMetadatName -Value $x
$getEnvName = $(Get-SoftwareName) + "_7ZIPLEVEL"
if ([System.Environment]::GetEnvironmentVariable($getEnvName) -ne "" -and $null -ne [System.Environment]::GetEnvironmentVariable($getEnvName)) {
$7zipLevel = [System.Environment]::GetEnvironmentVariable($getEnvName)
Write-Log "Compression level set to '$7zipLevel'"
} else {
$7zipLevel = "Normal"
}
$getEnvName = $(Get-SoftwareName) + "_ZIPFORMAT"
if ([System.Environment]::GetEnvironmentVariable($getEnvName) -ne "" -and $null -ne [System.Environment]::GetEnvironmentVariable($getEnvName)) {
$7zipFormat = [System.Environment]::GetEnvironmentVariable($getEnvName)
Write-Log "Compression format set to '$7zipFormat'"
} else {
$7zipFormat= "SevenZip"
$7zipFormat= "Zip"
}
Compress-7Zip -Path $SourceFolder -ArchiveFileName $ArchiveFile -Format $7zipFormat -CompressionLevel $7zipLevel -Filter $Filter
Compress-7Zip -Path $fullMetadatName -ArchiveFileName $ArchiveFile -PreserveDirectoryRoot -Format $7zipFormat -CompressionLevel $7zipLevel -Append
Remove-Item -Path $fullMetadatName
Close-Log
}

View File

@ -1,63 +0,0 @@
function ConvertFrom-Ckan
{
Param(
[Parameter(Mandatory)][String] $InputObject
)
$oCkan = ConvertFrom-Json -InputObject $InputObject
$oMarti = New-MartiDefinition
$oMarti.title = "Conversion from CKAN"
$oMarti.state = $oCkan.result.state
$oMarti.uid = $oCkan.result.id
$oMarti.contactPoint = $oCkan.result.contact_point
$oMarti.license = $oCkan.result.license_id
$oMarti.description = $oCkan.result.notes
$version = "1.1.0"
[System.Collections.ArrayList]$lresource = @()
$oCkan.result.resources | ForEach-Object {
$idx = $_.url.LastIndexOf("/")
if ($idx -gt 1) {
$name = $_.url.Substring(($idx+1))
} else {
$name = ""
}
$hash = New-MartiHash -Algorithm "SHA256" -FilePath "" -Value $_.hash
$oResource = [PSCustomObject]@{
title = $_.name
uid = $_.id
documentName = $name
issuedDate = $_.created
modified = $_.last_modified
state = $_.state
author = $oCkan.result.author
length = $_.size
hash = $hash
description = $_.description
url = $_.url
version = $version
format = $_.format
compression = ""
encryption = ""
}
$lresource += $oResource
}
$oMarti.resources = $lresource
return $oMarti
}

View File

@ -1,65 +1,12 @@
$script:LogPathName = ""
$script:SoftwareVersion = "0.0.1"
#. ..\..\..\source\powershell\MartiLQUtilities.ps1
$global:default_metaFile = "##marti##.json"
function Get-LogName {
$date = Get-Date -f "yyyy-MM-dd"
if (($null -eq $script:LogPathName) -or ($script:LogPathName -eq ""))
{
return $null
}
if (!(Test-Path -Path $script:LogPathName)) {
$null = New-Item -Path $script:LogPathName -ItemType Directory
}
$logName = $(Get-SoftwareName) + "_$date.log"
return Join-Path -Path $script:LogPathName -ChildPath $logName
}
. .\source\powershell\MartiLQUtilities.ps1
. .\source\powershell\MartiLQConfiguration.ps1
. .\source\powershell\MartiLQResource.ps1
. .\source\powershell\MartiLQAttribute.ps1
function Write-Log {
param(
[String] $LogEntry
)
$sFullPath = Get-LogName
$dateTime = Get-Date -f "yyyy-MM-dd HH:mm:ss"
if ($null -ne $sFullPath -and $sFullPath -ne "") {
if (!(Test-Path -Path $sFullPath)) {
Write-Host "Log path: $sFullPath"
$null = New-Item -Path $sFullPath -ItemType File
}
Add-Content -Path $sFullPath -Value "[$dateTime]. $LogEntry"
}
Write-Debug "[$dateTime]. $LogEntry"
}
function Open-Log {
$dateTime = Get-Date -f "yyyy-MM-dd HH:mm:ss"
Write-Log "***********************************************************************************"
Write-Log "* Start of processing: [$dateTime]"
Write-Log "***********************************************************************************"
}
function Close-Log {
$dateTime = Get-Date -f "yyyy-MM-dd HH:mm:ss"
Write-Log "***********************************************************************************"
Write-Log "* End of processing: [$dateTime]"
Write-Log "***********************************************************************************"
}
function Get-SoftwareName {
return [String] "MARTIREFERENCE"
}
@ -150,7 +97,7 @@ Param(
function Get-MartChildResource
function Get-MartiChildResource
{
Param(
[Parameter(Mandatory)][PSCustomObject] $Marti,
@ -165,7 +112,7 @@ function Get-MartChildResource
Write-Debug "Parameter: LogPath Value: $LogPath "
Open-Log
Write-Log "Function 'Get-MartiItem' parameters follow"
Write-Log "Function 'Get-MartiChildResource' parameters follow"
Write-Log "Parameter: ResourceName Value: $ResourceName "
Write-Log "Parameter: Format Value: $Format "
Write-Log ""
@ -235,3 +182,130 @@ function Get-MartiResource {
Close-Log
return $null
}
function ConvertFrom-Ckan
{
Param(
[Parameter(Mandatory)][String] $InputObject
)
$oCkan = ConvertFrom-Json -InputObject $InputObject
$oMarti = New-MartiDefinition
$oMarti.title = "Conversion from CKAN"
$oMarti.state = $oCkan.result.state
$oMarti.uid = $oCkan.result.id
$oMarti.contactPoint = $oCkan.result.contact_point
$oMarti.license = $oCkan.result.license_id
$oMarti.description = $oCkan.result.notes
$version = "1.1.0"
[System.Collections.ArrayList]$lresource = @()
$oCkan.result.resources | ForEach-Object {
$idx = $_.url.LastIndexOf("/")
if ($idx -gt 1) {
$name = $_.url.Substring(($idx+1))
} else {
$name = ""
}
$hash = New-MartiHash -Algorithm "SHA256" -FilePath "" -Value $_.hash
$oResource = [PSCustomObject]@{
title = $_.name
uid = $_.id
documentName = $name
issuedDate = $_.created
modified = $_.last_modified
state = $_.state
author = $oCkan.result.author
length = $_.size
hash = $hash
description = $_.description
url = $_.url
version = $version
format = $_.format
compression = ""
encryption = ""
}
$lresource += $oResource
}
$oMarti.resources = $lresource
return $oMarti
}
function Compress-MartiLQ
{
Param(
[Parameter(Mandatory)][String] $SourceFolder,
[Parameter(Mandatory)][String] $ArchiveFile,
[String] $Filter ="*",
[switch] $ExcludeHash,
[String] $LogPath
)
$script:LogPathName = $LogPath
Write-Debug "Parameter: LogPath Value: $LogPath "
Open-Log
Write-Log "Function 'Compress-MartiLQ' parameters follow"
Write-Log "Parameter: SourceFolder Value: $SourceFolder "
Write-Log "Parameter: ArchiveFile Value: $ArchiveFile "
Write-Log "Parameter: Filter Value: $Filter "
Write-Log ""
$marti_mri = $global:default_metaFile
$oMarti = New-MartiDefinition -SourceFolder $SourceFolder -Filter $Filter -LogPath $LogPath
$oMarti.description = "Sample execution"
$fullMetadatName = Join-Path -Path (Split-Path -Path $ArchiveFile -Parent) -ChildPath $marti_mri
$x = ConvertTo-Json -InputObject $oMarti
Add-Content -Path $fullMetadatName -Value $x
$getEnvName = $(Get-SoftwareName) + "_7ZIPLEVEL"
if ([System.Environment]::GetEnvironmentVariable($getEnvName) -ne "" -and $null -ne [System.Environment]::GetEnvironmentVariable($getEnvName)) {
$7zipLevel = [System.Environment]::GetEnvironmentVariable($getEnvName)
Write-Log "Compression level set to '$7zipLevel'"
} else {
$7zipLevel = "Normal"
}
$getEnvName = $(Get-SoftwareName) + "_ZIPFORMAT"
if ([System.Environment]::GetEnvironmentVariable($getEnvName) -ne "" -and $null -ne [System.Environment]::GetEnvironmentVariable($getEnvName)) {
$7zipFormat = [System.Environment]::GetEnvironmentVariable($getEnvName)
Write-Log "Compression format set to '$7zipFormat'"
} else {
$7zipFormat= "SevenZip"
$7zipFormat= "Zip"
}
Compress-7Zip -Path $SourceFolder -ArchiveFileName $ArchiveFile -Format $7zipFormat -CompressionLevel $7zipLevel -Filter $Filter
Compress-7Zip -Path $fullMetadatName -ArchiveFileName $ArchiveFile -PreserveDirectoryRoot -Format $7zipFormat -CompressionLevel $7zipLevel -Append
Remove-Item -Path $fullMetadatName
Close-Log
}

View File

@ -0,0 +1,2 @@

View File

@ -0,0 +1,6 @@
$script:SoftwareVersion = "0.0.1"
$global:default_metaFile = "##marti##.json"

View File

@ -1,4 +1,5 @@
function New-MartiResource {
Param(
[Parameter(Mandatory)][String] $SourcePath,
@ -42,7 +43,7 @@ Param(
documentName = $item.Name
issuedDate = Get-Date -f "yyyy-MM-ddTHH:mm:ss"
modified = $item.LastWriteTime.ToString("yyyy-MM-ddTHH:mm:ss")
expires = $expires -f "yyyy-MM-ddTHH:mm:ss"
expires = $expires.ToString("yyyy-MM-ddTHH:mm:ss")
state = "active"
author = ""
length = $item.Length
@ -482,3 +483,158 @@ function Set-MartiResourceAttributes {
function Compare-MartiResource {
Param(
[Parameter(Mandatory)][String] $DataSource,
[Parameter(Mandatory)][PSCustomObject] $Resource,
[String] $LogPath
)
$script:LogPathName = $LogPath
Write-Debug "Parameter: LogPath Value: $LogPath "
Open-Log
Write-Log "Function 'Compare-MartiResource' parameters follow"
Write-Log ""
if ($null -eq $Resource) {
$Global:MartiErrorId = "MRI2201"
$message = "No resource definition supplied"
Write-Log ($message + " " + $Global:MartiErrorId)
Close-Log
throw $message
}
if ($null -eq $DataSource -or $DataSource -eq "") {
$Global:MartiErrorId = "MRI2202"
$message = "No document supplied"
Write-Log ($message + " " + $Global:MartiErrorId)
Close-Log
throw $message
}
if ($DataSource.Length -le 1000) {
# Check if the name is a file
if (Test-Path -Path $DataSource) {
$inputData = Get-Content -Path $DataSource -Raw
Write-Host "Loading file $DataSource"
} else {
$inputData = $DataSource
}
} else {
$inputData = $DataSource
}
$formatProcessed = $false
[System.Collections.ArrayList]$lerror = @()
if ($Resource.format -eq "CSV") {
$formatProcessed = $true
$data = $inputData | ConvertFrom-Csv -Delim ','
$columns = ($data | get-member -type NoteProperty).count
$rows = @($data).count
$Resource.attributes | ForEach-Object {
if ($_.category -eq "dataset" -and $_.name -eq "records" -and $_.function -eq "count" -and $_.comparison -eq "EQ") {
if ($_.value -ne $rows) {
$oError = [PSCustomObject]@{
id = "MRI2203"
message = "Row count does not match"
found = "$rows"
expected = "$($_.value)"
}
$lerror += $oError
}
}
if ($_.category -eq "dataset" -and $_.name -eq "columns" -and $_.function -eq "count" -and $_.comparison -eq "EQ") {
if ($_.value -ne $columns) {
$oError = [PSCustomObject]@{
id = "MRI2204"
message = "Column count does not match"
found = "$columns"
expected = "$($_.value)"
}
$lerror += $oError
}
}
}
}
if ($Resource.format -eq "JSON") {
$formatProcessed = $true
$data = $inputData | ConvertFrom-Json
$rows = @($data.data.monitor).count
$item = $data.data.monitor[0]
$columns = ($item | get-member -type NoteProperty).count
$Resource.attributes | ForEach-Object {
if ($_.category -eq "dataset" -and $_.name -eq "records" -and $_.function -eq "count" -and $_.comparison -eq "EQ") {
if ($_.value -ne $rows) {
$oError = [PSCustomObject]@{
id = "MRI2203"
message = "Row count does not match"
found = "$rows"
expected = "$($_.value)"
}
$lerror += $oError
}
}
if ($_.category -eq "dataset" -and $_.name -eq "columns" -and $_.function -eq "count" -and $_.comparison -eq "EQ") {
if ($_.value -ne $columns) {
$oError = [PSCustomObject]@{
id = "MRI2204"
message = "Column count does not match"
found = "$columns"
expected = "$($_.value)"
}
$lerror += $oError
}
}
}
}
if (!$formatProcessed) {
$Global:MartiErrorId = "MRI2203"
$message = "Data format not supported"
Write-Log ($message + " " + $Global:MartiErrorId)
Close-Log
throw $message
}
$status = "OK"
if ($lerror.Count -gt 0) {
$status = "ERROR"
}
$oResult = [PSCustomObject]@{
status = $status
errors = $lerror
}
Close-Log
return $oResult
}

View File

@ -0,0 +1,61 @@
$script:LogPathName = ""
function Get-SoftwareName {
return [String] "MARTIREFERENCE"
}
function Get-LogName {
$date = Get-Date -f "yyyy-MM-dd"
if (($null -eq $script:LogPathName) -or ($script:LogPathName -eq ""))
{
return $null
}
if (!(Test-Path -Path $script:LogPathName)) {
$null = New-Item -Path $script:LogPathName -ItemType Directory
}
$logName = $(Get-SoftwareName) + "_$date.log"
return Join-Path -Path $script:LogPathName -ChildPath $logName
}
function Write-Log {
param(
[String] $LogEntry
)
$sFullPath = Get-LogName
$dateTime = Get-Date -f "yyyy-MM-dd HH:mm:ss"
if ($null -ne $sFullPath -and $sFullPath -ne "") {
if (!(Test-Path -Path $sFullPath)) {
Write-Host "Log path: $sFullPath"
$null = New-Item -Path $sFullPath -ItemType File
}
Add-Content -Path $sFullPath -Value "[$dateTime]. $LogEntry"
}
Write-Debug "[$dateTime]. $LogEntry"
}
function Open-Log {
$dateTime = Get-Date -f "yyyy-MM-dd HH:mm:ss"
Write-Log "***********************************************************************************"
Write-Log "* Start of processing: [$dateTime]"
Write-Log "***********************************************************************************"
}
function Close-Log {
$dateTime = Get-Date -f "yyyy-MM-dd HH:mm:ss"
Write-Log "***********************************************************************************"
Write-Log "* End of processing: [$dateTime]"
Write-Log "***********************************************************************************"
}

View File

@ -0,0 +1,28 @@
import os
import requests
import ftplib
from genericpath import getsize
from mlogging import mLogging
from mconfiguration import mConfiguration
class mUtility:
_oConfiguration = None
_Log = None
def __init__(self):
self._LogOpen = False
self._oConfiguration = mConfiguration()
self._Log = mLogging()
self._Log.SetConfig(self._oConfiguration.GetConfig("logPath"), self._oConfiguration.GetSoftwareName())
def SetConfig(self, Configuration):
self._oConfiguration = Configuration
self._Log.SetConfig(self._oConfiguration.GetConfig("logPath"), self._oConfiguration.GetSoftwareName())

View File

@ -1,6 +1,5 @@
. .\source\powershell\MartiLQ.ps1
. .\source\powershell\Compress-MartiLQ.ps1
try {
@ -8,7 +7,7 @@ try {
$oMarti = New-MartiChildItem -SourceFolder ".\docs" -Recurse -UrlPath ".\docs" -Filter "*" -LogPath ".\test\powershell\results\Logs"
$oMarti.description = "Sample execution"
$x = ConvertTo-Json -InputObject $oMarti
$x = ConvertTo-Json -InputObject $oMarti -Depth 6
Set-Content -Path ".\test\powershell\results\marti_test01.json" -Value $x
Write-Host "Test case #2"
@ -16,12 +15,12 @@ try {
Compress-MartiLQ -SourceFolder ".\docs" -Filter "*" -LogPath ".\test\powershell\results\Logs" -ArchiveFile $ArchiveFile
Write-Host "Test case #3"
$y = Get-MartiItem -MartiDefintiion $oMarti -Title "ckan" -Format "txt" -LogPath ".\test\powershell\results\Logs"
$y = Get-MartiChildResource -Marti $oMarti -Title "ckan" -Format "txt" -LogPath ".\test\powershell\results\Logs"
Write-Host "Get item Title: $($y.title)"
Write-Host "Get item Url: $($y.url)"
Write-Host "Test case #4"
$oMarti = New-MartiResource -SourcePath ".\docs\ckan.md" -LogPath ".\test\powershell\results\Logs"
$oMarti = New-MartiResource -SourcePath ".\docs\source\ckan.md" -LogPath ".\test\powershell\results\Logs"
$oMarti.description = "Sample execution for ckan"
$x = ConvertTo-Json -InputObject $oMarti

View File

@ -1,6 +1,5 @@
. .\source\powershell\MartiLQ.ps1
. .\source\powershell\ConvertFrom-Ckan.ps1
if (!(Test-Path -Path ".\test\powershell\results\data")) {
$null = New-Item -Path ".\test\powershell\results\data" -ItemType Directory