public int[] findEntityIds(Map<String, String> publicMetadata, String[] wildcardFields) throws RemoteException { int[] ids = ListUtils.toIntArray(getDataConfig().searchPublicMetadata(publicMetadata, wildcardFields)); Arrays.sort(ids); return ids; }
public WeaveRecordList getRows(String keyType, String[] keysArray) throws RemoteException { DataConfig dataConfig = getDataConfig(); DataEntityMetadata params = new DataEntityMetadata(); params.setPublicValues( PublicMetadata.ENTITYTYPE, EntityType.COLUMN, PublicMetadata.KEYTYPE, keyType); List<Integer> columnIds = new ArrayList<Integer>(dataConfig.searchPublicMetadata(params.publicMetadata, null)); if (columnIds.size() > MAX_COLUMN_REQUEST_COUNT) columnIds = columnIds.subList(0, MAX_COLUMN_REQUEST_COUNT); return DataService.getFilteredRows(ListUtils.toIntArray(columnIds), null, keysArray); }
@SuppressWarnings({"rawtypes", "unchecked"}) private Object[] getParamsFromMap(String methodName, Map params) { ExposedMethod exposedMethod = methodMap.get(methodName); String[] argNames = exposedMethod.paramNames; Class[] argTypes = exposedMethod.method.getParameterTypes(); Object[] argValues = new Object[argTypes.length]; Map extraParameters = null; // parameters that weren't mapped directly to method arguments // For each method parameter, get the corresponding url parameter value. if (argNames != null && params != null) { // TODO: check why params is null for (Object parameterName : params.keySet()) { Object parameterValue = params.get(parameterName); int index = ListUtils.findString((String) parameterName, argNames); if (index >= 0) { argValues[index] = parameterValue; } else if (!parameterName.equals(METHOD)) { if (extraParameters == null) extraParameters = new HashMap(); extraParameters.put(parameterName, parameterValue); } } } // support for a function having a single Map<String,String> parameter // see if we can find a Map arg. If so, set it to extraParameters if (argTypes != null) { for (int i = 0; i < argTypes.length; i++) { if (argTypes[i] == Map.class && argValues[i] == null) { // avoid passing a null Map to the function if (extraParameters == null) extraParameters = new HashMap<String, String>(); argValues[i] = extraParameters; extraParameters = null; break; } } } if (extraParameters != null) { System.out.println("Received servlet request: " + methodToString(methodName, argValues)); System.out.println("Unused parameters: " + extraParameters.entrySet()); } return argValues; }
/** * Use getEntities() instead. This function is provided for backwards compatibility only. * * @deprecated */ @Deprecated public int[] getEntityChildIds(int parentId) throws RemoteException { return ListUtils.toIntArray(getDataConfig().getChildIds(parentId)); }
/** * @param metadata The metadata query. * @return The id of the matching column. * @throws RemoteException Thrown if the metadata query does not match exactly one column. */ @Deprecated public AttributeColumnData getColumnFromMetadata(Map<String, String> metadata) throws RemoteException { if (metadata == null || metadata.size() == 0) throw new RemoteException("No metadata query parameters specified."); metadata.put(PublicMetadata.ENTITYTYPE, EntityType.COLUMN); final String DATATABLE = "dataTable"; final String NAME = "name"; // exclude these parameters from the query if (metadata.containsKey(NAME)) metadata.remove(PublicMetadata.TITLE); String minStr = metadata.remove(PublicMetadata.MIN); String maxStr = metadata.remove(PublicMetadata.MAX); String paramsStr = metadata.remove(PrivateMetadata.SQLPARAMS); DataConfig dataConfig = getDataConfig(); Collection<Integer> ids = dataConfig.searchPublicMetadata(metadata, null); // attempt recovery for backwards compatibility if (ids.size() == 0) { if (metadata.containsKey(DATATABLE) && metadata.containsKey(NAME)) { // try to find columns sqlTable==dataTable and sqlColumn=name Map<String, String> privateMetadata = new HashMap<String, String>(); String sqlTable = metadata.get(DATATABLE); String sqlColumn = metadata.get(NAME); for (int i = 0; i < 2; i++) { if (i == 1) sqlTable = sqlTable.toLowerCase(); privateMetadata.put(PrivateMetadata.SQLTABLE, sqlTable); privateMetadata.put(PrivateMetadata.SQLCOLUMN, sqlColumn); ids = dataConfig.searchPrivateMetadata(privateMetadata, null); if (ids.size() > 0) break; } } else if (metadata.containsKey(NAME) && Strings.equal(metadata.get(PublicMetadata.DATATYPE), DataType.GEOMETRY)) { metadata.put(PublicMetadata.TITLE, metadata.remove(NAME)); ids = dataConfig.searchPublicMetadata(metadata, null); } if (ids.size() == 0) throw new RemoteException("No column matches metadata query: " + metadata); } // warning if more than one column if (ids.size() > 1) { String message = String.format( "WARNING: Multiple columns (%s) match metadata query: %s", ids.size(), metadata); System.err.println(message); // throw new RemoteException(message); } // return first column int id = ListUtils.getFirstSortedItem(ids, DataConfig.NULL); double min = Double.NaN, max = Double.NaN; try { min = (Double) cast(minStr, double.class); } catch (Throwable t) { } try { max = (Double) cast(maxStr, double.class); } catch (Throwable t) { } String[] sqlParams = CSVParser.defaultParser.parseCSVRow(paramsStr, true); return getColumn(id, min, max, sqlParams); }
/** * Use getEntities() instead. This function is provided for backwards compatibility only. * * @deprecated */ @Deprecated public int[] getParents(int childId) throws RemoteException { int[] ids = ListUtils.toIntArray(getDataConfig().getParentIds(childId)); Arrays.sort(ids); return ids; }
/** * Tries to convert value to the given type * * @param value * @param type * @return value which may have been cast as the new type */ @SuppressWarnings({"unchecked", "rawtypes"}) protected Object cast(Object value, Class<?> type) { if (value == null) { if (type == double.class || type == Double.class) value = Double.NaN; else if (type == float.class || type == Float.class) value = Float.NaN; } else if (value instanceof String) { try { if (type == int.class || type == Integer.class) { value = Integer.parseInt((String) value); } else if (type == float.class || type == Float.class) { value = Float.parseFloat((String) value); } else if (type == double.class || type == Double.class) { value = Double.parseDouble((String) value); } else if (type == boolean.class || type == Boolean.class) { // value = Boolean.parseBoolean((String)value); value = ((String) (value)).equalsIgnoreCase("true"); } else if (type.isArray() || type == List.class) { String[][] table = CSVParser.defaultParser.parseCSV((String) value, true); if (table.length == 0) value = new String[0]; // empty else value = table[0]; // first row if (type == List.class) value = Arrays.asList((String[]) value); else value = cast(value, type); } else if (type == InputStream.class) { try { String temp = (String) value; value = (InputStream) new ByteArrayInputStream(temp.getBytes("UTF-8")); } catch (Exception e) { return null; } } } catch (NumberFormatException e) { // if number parsing fails, leave the original value untouched } } else if (value instanceof Boolean && type == boolean.class) { value = (boolean) (Boolean) value; } else if (value.getClass() == ArrayList.class) { value = cast(((ArrayList) value).toArray(), type); } else if (value.getClass().isArray()) { Object[] valueArray = (Object[]) value; if (type == List.class) { value = ListUtils.copyArrayToList(valueArray, new Vector()); } else if (type == Object[][].class) { Object[][] valueMatrix = new Object[valueArray.length][]; for (int i = 0; i < valueArray.length; i++) { valueMatrix[i] = (Object[]) valueArray[i]; } value = valueMatrix; } else if (type == String[][].class) { String[][] valueMatrix = new String[valueArray.length][]; for (int i = 0; i < valueArray.length; i++) { // cast Objects to Strings Object[] objectArray = (Object[]) valueArray[i]; valueMatrix[i] = ListUtils.copyStringArray(objectArray, new String[objectArray.length]); } value = valueMatrix; } else if (type == String[].class) { value = ListUtils.copyStringArray(valueArray, new String[valueArray.length]); } else if (type == double[][].class) { double[][] valueMatrix = new double[valueArray.length][]; for (int i = 0; i < valueArray.length; i++) { // cast Objects to doubles Object[] objectArray = (Object[]) valueArray[i]; valueMatrix[i] = ListUtils.copyDoubleArray(objectArray, new double[objectArray.length]); } value = valueMatrix; } else if (type == double[].class) { value = ListUtils.copyDoubleArray(valueArray, new double[valueArray.length]); } else if (type == int[][].class) { int[][] valueMatrix = new int[valueArray.length][]; for (int i = 0; i < valueArray.length; i++) { // cast Objects to doubles Object[] objectArray = (Object[]) valueArray[i]; valueMatrix[i] = ListUtils.copyIntegerArray(objectArray, new int[objectArray.length]); } value = valueMatrix; } else if (type == int[].class) { value = ListUtils.copyIntegerArray(valueArray, new int[valueArray.length]); } } else if (value instanceof Number) { if (type == int.class || type == Integer.class) { value = ((Number) value).intValue(); } else if (type == double.class || type == Double.class) { value = ((Number) value).doubleValue(); } else if (type == float.class || type == Float.class) { value = ((Number) value).floatValue(); } } return value; }