Add possible export for ap.org Overview document categoriser
Add possible export for ap.org Overview document categoriser

file:b/.gitignore (new)
  /admin/neo4jimporter/target/
  /admin/neo4jimporter/.settings/
  /nbproject/private/
<?php <?php
include_once("../lib/common.inc.php"); include_once("../lib/common.inc.php");
   
$query = 'update contractnotice set "parentCN" = null where "parentCN" = \'0\''; $query = 'update contractnotice set "parentCN" = null where "parentCN" = \'0\'';
$result = $conn->prepare($query); $result = $conn->prepare($query);
$result->execute(); $result->execute();
$query = 'update contractnotice set "childCN" = null where "childCN" = \'0\''; $query = 'update contractnotice set "childCN" = null where "childCN" = \'0\'';
$result = $conn->prepare($query); $result = $conn->prepare($query);
$result->execute(); $result->execute();
$query = 'select "CNID","parentCN" from contractnotice where "CNID" like \'%00_\' and "parentCN" is not null'; $query = 'select "CNID","parentCN" from contractnotice where "CNID" like \'%00_\' and "parentCN" is not null';
$result = $conn->prepare($query); $result = $conn->prepare($query);
$result->execute(); $result->execute();
foreach ($result->fetchAll() as $record) { foreach ($result->fetchAll() as $record) {
$oldCN = $record['CNID']; $oldCN = $record['CNID'];
$parentCN = substr($oldCN,0,-3); $parentCN = substr($oldCN,0,-3);
if ($parentCN == $record['parentCN']) { if ($parentCN == $record['parentCN']) {
$newCN = $parentCN . "-A". substr($oldCN,-1); $newCN = $parentCN . "-A". substr($oldCN,-1);
$updateresult = $conn->exec('UPDATE contractnotice SET "CNID" = $updateresult = $conn->exec('UPDATE contractnotice SET "CNID" =
\'' . $newCN . '\' where "CNID" = \'' . $oldCN . '\';'); \'' . $newCN . '\' where "CNID" = \'' . $oldCN . '\';');
echo "$oldCN => $newCN (from parent CN $parentCN) <br>\n"; echo "$oldCN => $newCN (from parent CN $parentCN) <br>\n";
} }
else { else {
echo "parent CN unexpected - $oldCN doesn't look like child of {$record['parentCN']} <br>\n"; // echo "parent CN unexpected - $oldCN doesn't look like child of {$record['parentCN']} <br>\n";
} }
} }
   
<
<?php <?php
   
include_once ("../lib/common.inc.php"); include_once ("../lib/common.inc.php");
function processFile($fpath, $tablename)  
{ $contractNoticeFields = array(
global $conn; "importFile",
$row = 1; "agencyName",
$handle = fopen($fpath, "r"); "parentCN",
//"t" mode string translates windows line breaks to unix "CNID",
$datamapping0711 = array( "publishDate",
"Agency" => "agencyName", "amendDate",
"Parent CN ID" => "parentCN", "contractStart",
"CN ID" => "CNID", "contractEnd",
"Publish Date" => "publishDate", "value",
"Amendment Date" => "amendDate", "description",
"Status" => "", "agencyID",
"StartDate" => "contractStart", "category",
"EndDate" => "contractEnd", "procurementMethod",
"Value" => "value", "atmID",
"Description" => "description", "SONID",
"Agency Ref Id" => "agencyID", "confidentialityContract",
"Category" => "category", "confidentialityContractReason",
"Procurement Method" => "procurementMethod", "confidentialityOutputs",
"ATM ID" => "atmID", "confidentialityOutputsReason",
"SON ID" => "SONID", "consultancy",
"Confidentiality - Contract" => "confidentialityContract", "consultancyReason",
"Confidentiality - Contract Reason(s)" => "confidentialityContractReason", "amendmentReason",
"Confidentiality - Outputs" => "confidentialityOutputs", "supplierName",
"Confidentiality - Outputs Reason(s)" => "confidentialityOutputsReason", "supplierAddress",
"Consultancy" => "consultancy", "supplierCity",
"Consultancy Reason(s)" => "consultancyReason", "supplierPostcode",
"Amendment Reason" => "amendmentReason", "supplierCountry",
"Supplier Name" => "supplierName", "supplierABNExempt",
"Supplier Address" => "supplierAddress", "supplierABN",
"Supplier City" => "supplierCity", "contactBranch",
"Supplier Postcode" => "supplierPostcode", "contactDivision",
"Supplier Country" => "supplierCountry", "contactPostcode"
"Supplier ABNExempt" => "supplierABNExempt", );
"Supplier ABN" => "supplierABN", $agencyFields = array(
"Agency Branch" => "contactBranch", "agencyName"
"Agency Divison" => "contactDivision", );
"Agency Postcode" => "contactPostcode", $supplierFields = array(
"" => "" "supplierName",
); "supplierAddress",
$headers; "supplierCity",
$contractNoticeFields = array( "supplierPostcode",
"importFile", "supplierCountry",
"agencyName", "supplierABNExempt",
"parentCN", "supplierABN"
"CNID", );
"publishDate", $contractNoticeInsertQ = 'INSERT INTO contractnotice ("' . implode('" , "', $contractNoticeFields) . '") VALUES ( ';
"amendDate", foreach ($contractNoticeFields as $key => $f) {
"contractStart", $contractNoticeInsertQ.= ($key == 0 ? "" : ", ") . "?";
"contractEnd", }
"value", $contractNoticeInsertQ.= ");";
"description", $contractNoticeInsertQ = $conn->prepare($contractNoticeInsertQ);
"agencyID",  
"category", $supplierInsertQ = 'INSERT INTO supplierdetails ("' . implode('" , "', $supplierFields) . '") VALUES ( ';
"procurementMethod", foreach ($supplierFields as $key => $f) {
"atmID", $supplierInsertQ.= ($key == 0 ? "" : ", ") . "?";
"SONID", }
"confidentialityContract", $supplierInsertQ.= ");";
"confidentialityContractReason", $supplierInsertQ = $conn->prepare($supplierInsertQ);
"confidentialityOutputs",  
"confidentialityOutputsReason", $agencyInsertQ = 'INSERT INTO agency_nametoabn ("' . implode('" , "', $agencyFields) . '") VALUES ( ';
"consultancy", foreach ($agencyFields as $key => $f) {
"consultancyReason", $agencyInsertQ.= ($key == 0 ? "" : ", ") . "?";
"amendmentReason", }
"supplierName", $agencyInsertQ.= ");";
"supplierAddress", $agencyInsertQ = $conn->prepare($agencyInsertQ);
"supplierCity",  
"supplierPostcode", function processFile($fpath, $tablename) {
"supplierCountry", global $conn, $contractNoticeQ, $supplierInsertQ, $agencyInsertQ;
"supplierABNExempt", $row = 1;
"supplierABN", $handle = fopen($fpath, "r");
"contactBranch", //"t" mode string translates windows line breaks to unix
"contactDivision", $datamapping0711 = array(
"contactPostcode" "Agency" => "agencyName",
); "Parent CN ID" => "parentCN",
$agencyFields = array( "CN ID" => "CNID",
"agencyName" "Publish Date" => "publishDate",
); "Amendment Date" => "amendDate",
$supplierFields = array( "Status" => "",
"supplierName", "StartDate" => "contractStart",
"supplierAddress", "EndDate" => "contractEnd",
"supplierCity", "Value" => "value",
"supplierPostcode", "Description" => "description",
"supplierCountry", "Agency Ref Id" => "agencyID",
"supplierABNExempt", "Category" => "category",
"supplierABN" "Procurement Method" => "procurementMethod",
); "ATM ID" => "atmID",
if ($tablename == "contractnotice") { "SON ID" => "SONID",
$contractNoticeInsertQ = 'INSERT INTO contractnotice ("' . implode('" , "', $contractNoticeFields) . '") VALUES ( '; "Confidentiality - Contract" => "confidentialityContract",
foreach ($contractNoticeFields as $key => $f) { "Confidentiality - Contract Reason(s)" => "confidentialityContractReason",
$contractNoticeInsertQ.= ($key == 0 ? "" : ", ") . "?"; "Confidentiality - Outputs" => "confidentialityOutputs",
} "Confidentiality - Outputs Reason(s)" => "confidentialityOutputsReason",
$contractNoticeInsertQ.= ");"; "Consultancy" => "consultancy",
$contractNoticeInsertQ = $conn->prepare($contractNoticeInsertQ); "Consultancy Reason(s)" => "consultancyReason",
} "Amendment Reason" => "amendmentReason",
else if ($tablename == "supplierdetails") { "Supplier Name" => "supplierName",
$supplierInsertQ = 'INSERT INTO supplierdetails ("' . implode('" , "', $supplierFields) . '") VALUES ( '; "Supplier Address" => "supplierAddress",
foreach ($supplierFields as $key => $f) { "Supplier City" => "supplierCity",
$supplierInsertQ.= ($key == 0 ? "" : ", ") . "?"; "Supplier Postcode" => "supplierPostcode",
} "Supplier Country" => "supplierCountry",
$supplierInsertQ.= ");"; "Supplier ABNExempt" => "supplierABNExempt",
$supplierInsertQ = $conn->prepare($supplierInsertQ); "Supplier ABN" => "supplierABN",