Skip to content

Commit

Permalink
Merge branch 'prerelease' into fix/lims-1068/oidc-discovery-endpoint-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gfrn authored Nov 2, 2023
2 parents 44b0dd0 + 9a0ad6f commit 5fa8803
Show file tree
Hide file tree
Showing 29 changed files with 498 additions and 254 deletions.
7 changes: 5 additions & 2 deletions api/config_sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
# CAS CA Cert (for SSO)
$cacert = '/etc/certs/ca-bundle.crt';

# ldap server, used for lookup and authentication (if using)
# ldap server, used for lookup and authentication (if using, set to null if not)
# Update the ldap(s) prefix, hostname and search settings as required
$ldap_server = 'ldaps://ldap.example.com';
$ldap_search = 'ou=people,dc=example,dc=com';
Expand Down Expand Up @@ -248,7 +248,10 @@
# Shipping service details
$use_shipping_service = null;
$use_shipping_service_incoming_shipments = null;
$shipping_service_url = null;
$shipping_service_api_url = null;
$shipping_service_api_user = null;
$shipping_service_api_password = null;
$shipping_service_app_url = null;
$shipping_service_links_in_emails = null;


Expand Down
8 changes: 7 additions & 1 deletion api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use SynchWeb\Database\DatabaseParent;
use SynchWeb\ImagingShared;
use SynchWeb\Dispatch;
use SynchWeb\Options;

require 'vendor/autoload.php';

Expand Down Expand Up @@ -71,8 +72,9 @@ function setupApplication($mode): Slim
$dhl_enable, $dhl_link, $scale_grid, $scale_grid_end_date, $preset_proposal, $timezone,
$valid_components, $enabled_container_types, $ifsummary;
$app->contentType('application/json');
$options = $app->container['options'];
$app->response()->body(json_encode(array(
'motd' => $motd,
'motd' => $options->get('motd', $motd),
'authentication_type' => $authentication_type,
'cas_url' => $cas_url,
'cas_sso' => $cas_sso,
Expand Down Expand Up @@ -145,4 +147,8 @@ function setupDependencyInjectionContainer($app)
$app->container->singleton('dispatch', function () use ($app) {
return new Dispatch($app, $app->container['db'], $app->container['user']);
});

$app->container->singleton('options', function () use ($app) {
return new Options($app->container['db']);
});
}
47 changes: 33 additions & 14 deletions api/scripts/mtz2map.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,35 @@ export CLIBD=$CCP4_MASTER/lib/data
export CCP4_SCR=/tmp
export root=$CCP4_MASTER/bin

if [ -f $1 ]; then
mtz=$1
else
if [ -f $1.gz ]; then
mtz=/tmp/$2_$3.mtz
gunzip -c $1.gz > $mtz
else
echo "No mtz file found"
exit
fi
fi

if [ $3 == 'dimple' -o $3 == 'mrbump' ]; then

if [ -f $4 ]; then
pdb=$4
else
if [ -f $4.gz ]; then
pdb=/tmp/$2_$3.pdb
gunzip -c $4.gz > $pdb
else
echo "No pdb file found"
exit
fi
fi

if [ $3 == 'dimple' ]; then
# fofc2="F1=F SIG1=SIGF PHI=PH2FOFCWT W=FOM"
# fofc="F1=F SIG1=SIGF PHI=PHFOFCWT W=FOM"
# fofc2="F1=F SIG1=SIGF PHI=PHWT W=FOM"
# fofc="F1=F SIG1=SIGF PHI=PHDELWT W=FOM"

if $root/mtzinfo $1 | grep -q PH2FOFCWT; then
if $root/mtzinfo $mtz | grep -q PH2FOFCWT; then
fofc2="F1=2FOFCWT SIG1=SIGF PHI=PH2FOFCWT"
fofc="F1=F SIG1=SIGF PHI=PHFOFCWT W=FOM"
else
Expand All @@ -37,7 +57,7 @@ fi

# F SIGF FC PHIC FC_ALL PHIC_ALL FWT PHWT DELFWT PHDELWT FOM FC_ALL_LS PHIC_ALL_LS

$root/fft HKLIN $1 MAPOUT "/tmp/$2_$3_2fofc.map.tmp" << eof
$root/fft HKLIN $mtz MAPOUT "/tmp/$2_$3_2fofc.map.tmp" << eof
title $2 2fofc
xyzlim asu
scale F1 1.0
Expand All @@ -46,11 +66,11 @@ $fofc2
end
eof

$root/mapmask MAPIN "/tmp/$2_$3_2fofc.map.tmp" MAPOUT "/tmp/$2_$3_2fofc.map" XYZIN "$4" << eof
$root/mapmask MAPIN "/tmp/$2_$3_2fofc.map.tmp" MAPOUT "/tmp/$2_$3_2fofc.map" XYZIN "$pdb" << eof
BORDER 5
eof

$root/fft HKLIN $1 MAPOUT "/tmp/$2_$3_fofc.map.tmp" << eof
$root/fft HKLIN $mtz MAPOUT "/tmp/$2_$3_fofc.map.tmp" << eof
title $2 fofc
xyzlim asu
scale F1 1.0
Expand All @@ -60,16 +80,17 @@ end
eof


$root/mapmask MAPIN "/tmp/$2_$3_fofc.map.tmp" MAPOUT "/tmp/$2_$3_fofc.map" XYZIN "$4" << eof
$root/mapmask MAPIN "/tmp/$2_$3_fofc.map.tmp" MAPOUT "/tmp/$2_$3_fofc.map" XYZIN "$pdb" << eof
BORDER 5
eof

gzip "/tmp/$2_$3_2fofc.map"
gzip "/tmp/$2_$3_fofc.map"

rm -f /tmp/$2_$3.pdb

else
$root/fft HKLIN $1 MAPOUT "/tmp/$2_$3.map" << eof
$root/fft HKLIN $mtz MAPOUT "/tmp/$2_$3.map" << eof
title $2 fofc
xyzlim asu
scale F1 1.0
Expand All @@ -78,10 +99,8 @@ F1=F SIG1=SIGF PHI=PHI W=FOM
end
eof

#$mm MAPIN "/tmp/$2_ep.map.tmp" MAPOUT "/tmp/$2_ep.map" XYZIN "$4" << eof
#BORDER 5
#eof

gzip "/tmp/$2_$3.map"

fi

rm -f /tmp/$2_$3.mtz
8 changes: 6 additions & 2 deletions api/src/Downstream/BigEPPhasing.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ function results() {
}

$image = $this->_get_image();
$dat['IMAGE'] = file_exists($image);
$dat['IMAGE'] = file_exists($image) || file_exists($image.'.gz');

$model = $this->_get_attachments('big_ep_model_ispyb.json');
$dat['HASMODEL'] = $model && file_exists($model['FILE']);
$dat['HASMODEL'] = $model && (file_exists($model['FILE']) || file_exists($model['FILE'].'.gz'));
if ($model) {
if (file_exists($model['FILE'])) {
$json_str = file_get_contents($model['FILE']);
} elseif (file_exists($model['FILE'].'.gz')) {
$json_str = gzdecode(file_get_contents($model['FILE'].'.gz'));
}
if (isset($json_str)) {
$json_data = json_decode($json_str, true);
foreach (
array(
Expand Down
142 changes: 77 additions & 65 deletions api/src/Downstream/Type/FastEp.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,83 +16,95 @@ function results() {
$pdb = $this->_get_attachments("sad_fa.pdb");
if ($pdb) {
if (file_exists($pdb["FILE"])) {
$pdb = file_get_contents($pdb["FILE"]);
foreach (explode("\n", $pdb) as $l) {
if (strpos($l, 'HETATM') !== false) {
$parts = preg_split('/\s+/', $l);
array_push($ats, array(
$parts[1],
$parts[5],
$parts[6],
$parts[7],
$parts[8],
));
}
}
$pdb_cont = file_get_contents($pdb["FILE"]);
} elseif (file_exists($pdb['FILE'].'.gz')) {
$pdb_cont = gzdecode(file_get_contents($pdb['FILE'].'.gz'));
}
}

$dat['ATOMS'] = array_slice($ats, 0, 5);
if (isset($pdb_cont)) {
foreach (explode("\n", $pdb_cont) as $l) {
if (strpos($l, 'HETATM') !== false) {
$parts = preg_split('/\s+/', $l);
array_push($ats, array(
$parts[1],
$parts[5],
$parts[6],
$parts[7],
$parts[8],
));
}
}

$dat['ATOMS'] = array_slice($ats, 0, 5);

}

$lst = $this->_get_attachments("sad.lst");
if ($lst) {
if (file_exists($lst['FILE'])) {
$p1 = array();
$p2 = array();

$lst = file_get_contents($lst['FILE']);
$graph_vals = 0;
$gvals = array();
foreach (explode("\n", $lst) as $l) {
if (
strpos(
$l,
'Estimated mean FOM and mapCC as a function of resolution'
) !== false
) {
$graph_vals = 1;
}

if ($graph_vals && $graph_vals < 5) {
array_push($gvals, $l);
$graph_vals++;
}

if (
preg_match(
'/ Estimated mean FOM = (\d+.\d+)\s+Pseudo-free CC = (\d+.\d+)/',
$l,
$mat
)
) {
$dat['FOM'] = floatval($mat[1]);
$dat['CC'] = floatval($mat[2]);
}
$lst_cont = file_get_contents($lst['FILE']);
} elseif (file_exists($lst['FILE'].'.gz')) {
$lst_cont = gzdecode(file_get_contents($lst['FILE'].'.gz'));
}
}

if (isset($lst_cont)) {
$p1 = array();
$p2 = array();

$graph_vals = 0;
$gvals = array();
foreach (explode("\n", $lst_cont) as $l) {
if (
strpos(
$l,
'Estimated mean FOM and mapCC as a function of resolution'
) !== false
) {
$graph_vals = 1;
}

if (sizeof($gvals) > 0) {
$x = array_map(
'floatval',
array_slice(explode(' - ', $gvals[1]), 1)
);
$y = array_map(
'floatval',
array_slice(preg_split('/\s+/', $gvals[2]), 2)
);
$y2 = array_map(
'floatval',
array_slice(preg_split('/\s+/', $gvals[3]), 2)
);

foreach ($x as $i => $v) {
array_push($p1, array(1.0 / pow($v, 2), $y[$i]));
array_push($p2, array(1.0 / pow($v, 2), $y2[$i]));
}
if ($graph_vals && $graph_vals < 5) {
array_push($gvals, $l);
$graph_vals++;
}

$dat['PLOTS']['FOM'] = $p1;
$dat['PLOTS']['CC'] = $p2;
if (
preg_match(
'/ Estimated mean FOM = (\d+.\d+)\s+Pseudo-free CC = (\d+.\d+)/',
$l,
$mat
)
) {
$dat['FOM'] = floatval($mat[1]);
$dat['CC'] = floatval($mat[2]);
}
}

if (sizeof($gvals) > 0) {
$x = array_map(
'floatval',
array_slice(explode(' - ', $gvals[1]), 1)
);
$y = array_map(
'floatval',
array_slice(preg_split('/\s+/', $gvals[2]), 2)
);
$y2 = array_map(
'floatval',
array_slice(preg_split('/\s+/', $gvals[3]), 2)
);

foreach ($x as $i => $v) {
array_push($p1, array(1.0 / pow($v, 2), $y[$i]));
array_push($p2, array(1.0 / pow($v, 2), $y2[$i]));
}
}

$dat['PLOTS']['FOM'] = $p1;
$dat['PLOTS']['CC'] = $p2;

}

$results = new DownstreamResult($this);
Expand Down
10 changes: 7 additions & 3 deletions api/src/Model/Services/AssignData.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace SynchWeb\Model\Services;

use SynchWeb\Utils;

class AssignData
{
private $db;
Expand Down Expand Up @@ -85,9 +87,10 @@ function updateDewar($dewarId, $status)

function deactivateDewar($dewarId)
{
$this->updateDewarHistory($dewarId, 'unprocessing');
$location = $this->db->pq("SELECT storagelocation FROM dewar WHERE dewarid=:1", array($dewarId));
$this->updateDewarHistory($dewarId, 'unprocessing', $location[0]['STORAGELOCATION']);

$conts = $this->db->pq("SELECT containerid as id FROM container WHERE dewarid=:1", array($dewarId));
$conts = $this->db->pq("SELECT containerid FROM container WHERE dewarid=:1", array($dewarId));
foreach ($conts as $container)
{
$this->updateContainerAndHistory($container['CONTAINERID'], 'at facility', '', '');
Expand All @@ -99,9 +102,10 @@ function updateDewarHistory($did, $status, $beamline = null, $additionalStatusDe
$st = $status;
if ($additionalStatusDetail)
$st .= ' (' . $additionalStatusDetail . ')';
$loc = Utils::getValueOrDefault($beamline, '');
$this->db->pq("INSERT INTO dewartransporthistory
(dewarid, dewarstatus, storagelocation, arrivaldate)
VALUES (:1, :2, :3, CURRENT_TIMESTAMP)", array($did, $st, $beamline));
VALUES (:1, :2, :3, CURRENT_TIMESTAMP)", array($did, $st, $loc));

$this->updateDewar($did, $status);
}
Expand Down
2 changes: 1 addition & 1 deletion api/src/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private function _retrieve() {

$this->options = array();
foreach ($options as $o) {
$this->options[$o['NAME']] = unserialize($o['VALUE']);
$this->options[$o['NAME']] = $o['VALUE'];
if ($o['UI'] == 1) $this->public[$o['NAME']] = $this->options[$o['NAME']];

}
Expand Down
4 changes: 4 additions & 0 deletions api/src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,10 @@ function _ldap_search($search, $email = False)
global $ldap_server, $ldap_search;

$ret = array();
if (is_null($ldap_server)) {
error_log("Ldap server is not configured, not looking up user.");
return $ret;
}
$ds = ldap_connect($ldap_server);
if ($ds)
{
Expand Down
2 changes: 1 addition & 1 deletion api/src/Page/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function _add_contact() {
foreach ($lfields as $i => $f) {
if ($this->has_arg($f)) {
$c = $f == 'LABNAME' ? 'NAME' : $f;
$this->db->pq('UPDATE laboratory SET '.$c.'=:1 WHERE laboratoryid=:2', array($this->arg($f), $lab['LABORATORYID']));
$this->db->pq('UPDATE laboratory SET '.$c.'=:1 WHERE laboratoryid=:2', array($this->arg($f), $lab[0]['LABORATORYID']));
}
}
}
Expand Down
Loading

0 comments on commit 5fa8803

Please sign in to comment.