Skip to content

Commit

Permalink
Firefly-1252: Merge PR #1392 from FIREFLY-1252-spacial-missing
Browse files Browse the repository at this point in the history
Firefly-1252: spacial missing
  • Loading branch information
robyww authored Jun 7, 2023
2 parents ebddb93 + 5bbc10a commit eccd53f
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
*/
package edu.caltech.ipac.firefly.server.query;

import edu.caltech.ipac.firefly.core.background.JobInfo;
import edu.caltech.ipac.firefly.data.TableServerRequest;
import edu.caltech.ipac.firefly.server.ServerContext;
import edu.caltech.ipac.firefly.server.network.HttpServiceInput;
import edu.caltech.ipac.firefly.server.util.QueryUtil;
import edu.caltech.ipac.table.DataGroup;
import edu.caltech.ipac.table.DataType;
import edu.caltech.ipac.table.TableUtil;
Expand Down Expand Up @@ -79,4 +81,9 @@ public HttpServiceInput createInput(TableServerRequest request) throws DataAcces
}
return inputs;
}

@Override
public DataGroup getResult(TableServerRequest request) throws DataAccessException {
return getTableResult(getJobUrl() + "/results/result", QueryUtil.getTempDir(request));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ static String getFilename(String urlStr) {
//====================================================================
// UWS utils
//====================================================================
private static DataAccessException createDax(String url, String title, String errMsg) {
static DataAccessException createDax(String url, String title, String errMsg) {
String msg = String.format("%s from the URL: [%s]", title, url);
if (errMsg != null) msg += "\n\t with exception: " + errMsg;
return new DataAccessException(msg);
Expand Down
8 changes: 4 additions & 4 deletions src/firefly/js/charts/ui/ColumnOrExpression.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ function parseSuggestboxContent(text) {
return {token, priorContent};
}

export function getColValidator(cols, required=true, canBeExpression=true) {
const DEFAULT_MSG= 'Can not be empty. Please provide value or expression';

export function getColValidator(cols, required=true, canBeExpression=true, message=DEFAULT_MSG) {
const colNames = cols.map((colVal) => {return colVal.name;});
return (val) => {
let retval = {valid: true, message: ''};
if (!val) {
if (required) {
return {valid: false, message: 'Can not be empty. Please provide value or expression'};
}
if (required) return {valid: false, message};
} else if (colNames.indexOf(val) < 0) {
if (canBeExpression) {
const expr = new Expression(val, colNames);
Expand Down
16 changes: 11 additions & 5 deletions src/firefly/js/ui/tap/SpatialSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,23 @@ export function SpatialSearch({cols, serviceUrl, serviceLabel, columnsModel, tab
const columns = searchParams.uploadInfo.columns;
const centerCols = findTableCenterColumns({tableData:{columns}}) ?? {};
const {lonCol='', latCol=''}= centerCols;
setVal(UploadCenterLonColumns, lonCol, {validator: getColValidator(searchParams.uploadInfo.columns, true, false), valid: true});
setVal(UploadCenterLatColumns, latCol, {validator: getColValidator(searchParams.uploadInfo.columns, true, false), valid: true});
const errMsg= 'Upload tables require identifying spatial columns containing equatorial coordinates. Please provide column names.';
setVal(UploadCenterLonColumns, lonCol, {validator: getColValidator(searchParams.uploadInfo.columns, true, false,errMsg), valid: true});
setVal(UploadCenterLatColumns, latCol, {validator: getColValidator(searchParams.uploadInfo.columns, true, false,errMsg), valid: true});
setUploadInfo(searchParams.uploadInfo);
checkHeaderCtl.setPanelActive(true);
}
}, [searchParams.radiusInArcSec, searchParams.wp, searchParams.corners, searchParams.uploadInfo]);


useEffect(() => {
const {lon,lat} = formCenterColumns(columnsModel);
setVal(CenterLonColumns, lon, {validator: getColValidator(cols, true, false), valid: true});
setVal(CenterLatColumns, lat, {validator: getColValidator(cols, true, false), valid: true});
const errMsg= 'Spatial searches require identifying table columns containing equatorial coordinates. Please provide column names.';
setVal(CenterLonColumns, lon, {validator: getColValidator(cols, true, false, errMsg), valid: true});
setVal(CenterLatColumns, lat, {validator: getColValidator(cols, true, false, errMsg), valid: true});
const noDefaults= !lon || !lat;
setVal(posOpenKey, (noDefaults) ? 'open' : 'closed');
if (noDefaults) checkHeaderCtl.setPanelActive(false);
checkHeaderCtl.setPanelOpen(!noDefaults);
setPosOpenMsg(noDefaults?'':TAB_COLUMNS_MSG);
}, [columnsModel, obsCoreEnabled]);

Expand Down Expand Up @@ -717,6 +720,9 @@ function makeSpatialConstraints(columnsModel, obsCoreEnabled, fldObj, uploadInfo
const cenLat= cenLatField?.value;
errList.checkForError(cenLonField);
errList.checkForError(cenLatField);
if (!cenLon && !cenLat) errList.addError('Lon and Lat columns are not set');
else if (!cenLon) errList.addError('Lon column is not set');
else if (!cenLat) errList.addError('Lat column is not set');
const ucdCoord = getUCDCoord(columnsModel, cenLon);
const worldSys = posCol[ucdCoord.key].coord;
const adqlCoordSys = posCol[ucdCoord.key].adqlCoord;
Expand Down
3 changes: 3 additions & 0 deletions src/firefly/js/ui/tap/TableSearchHelpers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,12 @@ export function makeCollapsibleCheckHeader(base) {

retObj.CollapsibleCheckHeader= ({title,helpID,message,initialStateOpen, initialStateChecked,children}) => {
const [getPanelActive, setPanelActive] = useFieldGroupValue(panelCheckKey);// eslint-disable-line react-hooks/rules-of-hooks
const [getPanelOpenStatus, setPanelOpenStatus] = useFieldGroupValue(panelKey);// eslint-disable-line react-hooks/rules-of-hooks
const isActive= getPanelActive() === panelValue;
retObj.isPanelActive= () => getPanelActive() === panelValue;
retObj.setPanelActive= (active) => setPanelActive(active ? panelValue : '');
retObj.isPanelOpen= () => getPanelOpenStatus() === 'open';
retObj.setPanelOpen= (open) => setPanelOpenStatus(open?'open':'close');
return (
<InternalCollapsibleCheckHeader {...{title, helpID, checkKey:panelCheckKey, fieldKey:panelKey,
message: isActive ? message:'', initialStateChecked, panelValue,
Expand Down
21 changes: 14 additions & 7 deletions src/firefly/js/ui/tap/TapUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,20 @@ export const getAsEntryForTableName= (tableName) => tableName?.[0] ?? 'x';
function mergeAdditionalServices(tapServices, additional) {
if (!hasElements(additional)) return tapServices;

const modifiedOriginal= tapServices.map( (t) => {
const match= additional.find( (a) => a.label===t.label);
return match ? {...t,...match} : t;
});
const trulyAdditional= additional.filter( (a) => !tapServices.find( (t) => t.label===a.label) );

return [...trulyAdditional,...modifiedOriginal];
const mergeAdditional= additional.map( (a) => {
if (a.hide) return false;
const originalEntry= tapServices.find( (t) => a.label===t.label);
return originalEntry ? {...originalEntry, ...a} : a;
}).filter( (s) => s);

const unmodifiedOriginal= tapServices
.map( (t) => {
const match= additional.find( (a) => a.label===t.label);
return !match && t;
})
.filter( (s) => s);

return [...mergeAdditional,...unmodifiedOriginal];
}

export function getTapServices(webApiUserAddedService) {
Expand Down
25 changes: 19 additions & 6 deletions src/firefly/js/ui/tap/TemportalSearch.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {useContext, useEffect, useState} from 'react';
import PropTypes from 'prop-types';
import {ColsShape, ColumnFld, getColValidator} from '../../charts/ui/ColumnOrExpression.jsx';
import {getColumnIdx} from '../../tables/TableUtil.js';
import {FieldGroupCtx, ForceFieldGroupValid} from '../FieldGroup.jsx';
import {useFieldGroupRerender, useFieldGroupWatch} from '../SimpleComponent.jsx';
import {checkExposureTime} from '../TimeUIUtil.js';
Expand Down Expand Up @@ -76,6 +77,18 @@ const {CollapsibleCheckHeader, collapsibleCheckHeaderKeys}= checkHeaderCtl;

const fldAry=[TimeTo,TimeFrom,TemporalColumns];

export function findTimeColumn(columnsTable) {
const ucdIdx= getColumnIdx(columnsTable,'ucd',true);
const nIdx= getColumnIdx(columnsTable,'column_name',true);
const unitIdx= getColumnIdx(columnsTable,'unit',true);
if (ucdIdx===-1 || nIdx===-1) return;
const timeRows= columnsTable.tableData.data.filter( (row) => row[ucdIdx]?.includes('time.epoch') && row[unitIdx].startsWith('d'));
if (!timeRows.length) return;
const mainRows= timeRows.filter( (row) => row[ucdIdx]?.includes('meta.main') && row[unitIdx].startsWith('d'));
return mainRows.length ? mainRows[0][nIdx] : timeRows[0][nIdx];
}


/**
*
* @param props
Expand All @@ -86,7 +99,7 @@ const fldAry=[TimeTo,TimeFrom,TemporalColumns];
export function TemporalSearch({cols, columnsModel}) {
const [constraintResult, setConstraintResult] = useState({});

const {setFld,getVal,makeFldObj}= useContext(FieldGroupCtx);
const {setFld,setVal,getVal,makeFldObj}= useContext(FieldGroupCtx);
const {setConstraintFragment}= useContext(ConstraintContext);
useFieldGroupRerender([...fldAry, ...collapsibleCheckHeaderKeys]); // force rerender on any change
const timeCol= getVal(TemporalColumns);
Expand All @@ -97,10 +110,7 @@ export function TemporalSearch({cols, columnsModel}) {
([tcVal],isInit) => {
if (!tcVal) return;
const timeColumns = tcVal.split(',').map( (c) => c.trim()) ?? [];
if (timeColumns.length === 1) {
if (!isInit) checkHeaderCtl.setPanelActive(true);
}
else {
if (timeColumns.length > 1) {
setFld(TemporalColumns, {value:tcVal, valid:false, message: 'you may only choose one column'});
}
});
Expand All @@ -117,7 +127,10 @@ export function TemporalSearch({cols, columnsModel}) {


useEffect(() => {
setFld(TemporalColumns, {validator: getColValidator(cols, true, false), valid: true});
const timeCol= findTimeColumn(columnsModel) ?? '';
const errMsg= 'Temporal searches require identifying a table column containing a time in MJD. Please provide a column name.';
setVal(TemporalColumns, timeCol, {validator: getColValidator(cols, true, false, errMsg), valid: true});
checkHeaderCtl.setPanelOpen(Boolean(timeCol));
}, [columnsModel]);


Expand Down

0 comments on commit eccd53f

Please sign in to comment.