15
15
import java .io .File ;
16
16
import java .io .IOException ;
17
17
import java .util .List ;
18
+ import java .util .regex .Pattern ;
18
19
19
20
/**
20
21
* @author tatianag
@@ -34,6 +35,9 @@ public class UserCatalogQuery extends DynQueryProcessor {
34
35
"starid" // PCRS
35
36
};
36
37
38
+ private static Pattern raP = Pattern .compile ("(^|[-_ ])ra($|[^\\ p{Alpha}])" );
39
+ private static Pattern decP = Pattern .compile ("(^|[-_ ])dec($|[^\\ p{Alpha}])" );
40
+
37
41
38
42
39
43
protected File loadDynDataFile (TableServerRequest req ) throws IOException , DataAccessException {
@@ -56,22 +60,11 @@ public void prepareTableMeta(TableMeta meta, List<DataType> columns, ServerReque
56
60
57
61
58
62
public static void addCatalogMeta (TableMeta meta , List <DataType > columns , ServerRequest request ) {
59
- TableMeta .LonLatColumns llc ;
60
-
61
- String lonCol = null , latCol = null ;
62
- for (DataType col : columns ) {
63
- if (col .getKeyName ().equalsIgnoreCase (RA )) lonCol = col .getKeyName ();
64
- if (col .getKeyName ().equalsIgnoreCase (DEC )) latCol = col .getKeyName ();
65
63
66
64
67
- if (!StringUtils .isEmpty (lonCol ) && !StringUtils .isEmpty (latCol )) {
68
- llc = new TableMeta .LonLatColumns (lonCol , latCol , CoordinateSys .EQ_J2000 );
69
- meta .setLonLatColumnAttr (MetaConst .CATALOG_COORD_COLS , llc );
70
- break ;
71
- }
72
- }
73
- boolean catalogDataFound = (lonCol !=null && latCol !=null );
74
- if (catalogDataFound ) {
65
+ TableMeta .LonLatColumns llc = findLonLatCols (columns , (TableServerRequest ) request );
66
+ if (llc != null ) {
67
+ meta .setLonLatColumnAttr (MetaConst .CATALOG_COORD_COLS , llc );
75
68
meta .setAttribute (MetaConst .CATALOG_OVERLAY_TYPE , "USER" );
76
69
meta .setAttribute (MetaConst .DATA_PRIMARY , "False" );
77
70
}
@@ -80,6 +73,26 @@ public static void addCatalogMeta(TableMeta meta, List<DataType> columns, Server
80
73
if (name != null ) meta .setAttribute (MetaConst .CATALOG_TARGET_COL_NAME , name );
81
74
}
82
75
76
+ private static TableMeta .LonLatColumns findLonLatCols (List <DataType > columns , TableServerRequest request ) {
77
+ String lonCol = null , latCol = null ;
78
+ TableMeta .LonLatColumns llc = TableMeta .LonLatColumns .parse (request .getMeta (MetaConst .CATALOG_COORD_COLS ));
79
+ if (llc == null ) {
80
+ // guess best ra/dec columns
81
+ for (DataType col : columns ) {
82
+ String cname = col .getKeyName ();
83
+ if (cname .equalsIgnoreCase (RA )) lonCol = cname ;
84
+ if (cname .equalsIgnoreCase (DEC )) latCol = cname ;
85
+
86
+ if (lonCol == null && raP .matcher (cname ).find ()) lonCol = cname ;
87
+ if (latCol == null && decP .matcher (cname ).find ()) latCol = cname ;
88
+ }
89
+ if (lonCol != null && latCol != null ) {
90
+ llc = new TableMeta .LonLatColumns (lonCol , latCol , CoordinateSys .EQ_J2000 );
91
+ }
92
+ }
93
+ return llc ;
94
+ }
95
+
83
96
private static String findTargetName (List <DataType > columns ) {
84
97
String cname ;
85
98
String finalName = null ;
0 commit comments