Exemplo n.º 1
0
  public JSONArray validateFields(MultivaluedMap<String, String> parameters) {
    JSONArray validationErrors = new JSONArray();

    // Dataset Validation ---------------------------------------------
    String datasetMetadata = parameters.get("meta").get(0);

    if (datasetMetadata != null) {
      datasetMetadata = URLDecoder.decode(datasetMetadata);
      try {
        if ((!datasetMetadata.equals("")) && (!datasetMetadata.equals("[]"))) {
          JSONObject metadataObject = JSONUtils.toJSONObject(datasetMetadata);
          JSONArray columnsMetadataArray = metadataObject.getJSONArray("columns");

          for (int j = 0; j < columnsMetadataArray.length(); j++) {
            JSONObject columnJsonObject = columnsMetadataArray.getJSONObject(j);
            String columnName = columnJsonObject.getString("column");
            if (columnJsonObject.getString("pname").equalsIgnoreCase("type")) {
              if (columnName == null) {
                validationErrors.put(
                    new JSONObject("{message: 'Validation error: Column name cannot be null'}"));
              } /* else if(Pattern.compile("\\s").matcher(columnName).find()){
                	validationErrors.put(new JSONObject("{message: 'Validation error: Space character not allowed for column name "+ columnName + "'}"));
                }else if(Pattern.compile("[ÀÈÌÒÙàèìòùÁÉÍÓÚÝáéíóúýÂÊÎÔÛâêîôûÃÑÕãñõÄËÏÖÜŸäëïöüŸ¡¿çÇŒœßØøÅåÆæÞþÐðÐð'.,&#@:?!()$\\/]").matcher(columnName).find()){
                	validationErrors.put(new JSONObject("{message: 'Validation error: Special characters not allowed for column name "+ columnName + "'}"));
                } */
            }
            String propertyName = columnJsonObject.getString("pname");
            if (propertyName == null) {
              validationErrors.put(
                  new JSONObject("{message: 'Validation error: Property name cannot be null'}"));
            } /* else if( Pattern.compile("\\s").matcher(propertyName).find()){
              	validationErrors.put(new JSONObject("{message: 'Validation error: Space character not allowed for Property name "+ propertyName + "'}"));
              }else if( Pattern.compile("[ÀÈÌÒÙàèìòùÁÉÍÓÚÝáéíóúýÂÊÎÔÛâêîôûÃÑÕãñõÄËÏÖÜŸäëïöüŸ¡¿çÇŒœßØøÅåÆæÞþÐðÐð'.,&#@:?!()$\\/]").matcher(propertyName).find()){
              	validationErrors.put(new JSONObject("{message: 'Validation error: Special characters not allowed for Property name "+ propertyName + "'}"));
              } */
            String propertyValue = columnJsonObject.getString("pvalue");
          }
        }

      } catch (JsonMappingException e1) {
        logger.error(e1.getMessage());
      } catch (JsonParseException e1) {
        logger.error(e1.getMessage());
      } catch (JSONException e1) {
        logger.error(e1.getMessage());
      } catch (IOException e1) {
        logger.error(e1.getMessage());
      }
    }
    return validationErrors;
  }
Exemplo n.º 2
0
  // returns true if the dataset is geospazial
  public static boolean hasGeoHierarchy(String meta)
      throws JsonMappingException, JsonParseException, JSONException, IOException {

    JSONObject metadataObject = JSONUtils.toJSONObject(meta);
    if (metadataObject == null) return false;

    JSONArray columnsMetadataArray = metadataObject.getJSONArray("columns");

    for (int j = 0; j < columnsMetadataArray.length(); j++) {
      JSONObject columnJsonObject = columnsMetadataArray.getJSONObject(j);
      //				String columnName = columnJsonObject.getString("column");
      String propertyName = columnJsonObject.getString("pname");
      String propertyValue = columnJsonObject.getString("pvalue");

      if (propertyName.equalsIgnoreCase("hierarchy")) {
        if (propertyValue.equalsIgnoreCase("geo")) {
          return true;
        }
      }
    }
    return false;
  }