Package org.openmhealth.reference.domain

Examples of org.openmhealth.reference.domain.Schema


    else {
      setServiced();
    }
   
    // Get the schema.
    Schema schema =
      Registry.getInstance().getSchema(schemaId, schemaVersion);
   
    // Make sure the schema exists.
    if(schema == null) {
      throw
        new NoSuchSchemaException(
          "The schema with id '" +
            schemaId +
            "' and version '" +
            schemaVersion +
            "' does not exist.");
    }
   
    // Convert the result to a map.
    ObjectMapper mapper = new ObjectMapper();
    // We need to suppress Java's type erasure. :(
    @SuppressWarnings("unchecked")
    Map<String, Object> metaData =
      mapper.convertValue(schema, Map.class);
   
    // Remove the schema from the meta-data.
    metaData.remove(Schema.JSON_KEY_SCHEMA);
   
    // Save the meta-data.
    setMetaData(metaData);
   
    // Set the schema itself as the data.
    setData(schema.getSchema());
  }
View Full Code Here


            schemaId +
            "', and version, '" +
            version +
            "', pair is unknown.");
    }
    Schema schema = schemas.iterator().next();
   
    // Get the user that owns this token.
    User requestingUser = authToken.getUser();
   
    // Parse the data.
    JsonNode dataNode;
    try {
      dataNode =
        JSON_FACTORY
          .createJsonParser(data).readValueAs(JsonNode.class);
    }
    catch(JsonParseException e) {
      throw new OmhException("The data was not well-formed JSON.", e);
    }
    catch(JsonProcessingException e) {
      throw new OmhException("The data was not well-formed JSON.", e);
    }
    catch(IOException e) {
      throw new OmhException("The data could not be read.", e);
    }
   
    // Make sure it is a JSON array.
    if(! (dataNode instanceof ArrayNode)) {
      throw new OmhException("The data was not a JSON array.");
    }
    ArrayNode dataArray = (ArrayNode) dataNode;
   
    // Get the number of data points.
    int numDataPoints = dataArray.size();
   
    // Create the result list of data points.
    List<Data> dataPoints = new ArrayList<Data>(numDataPoints);
   
    // Create a new ObjectMapper that will be used to convert the meta-data
    // node into a MetaData object.
    ObjectMapper mapper = new ObjectMapper();
   
    // For each element in the array, be sure it is a JSON object that
    // represents a valid data point for this schema.
    for(int i = 0; i < numDataPoints; i++) {
      // Get the current data point.
      JsonNode dataPoint = dataArray.get(i);
     
      // Validate that it is a JSON object.
      if(! (dataPoint instanceof ObjectNode)) {
        throw
          new OmhException(
            "A data point was not a JSON object: " + i);
      }
      ObjectNode dataObject = (ObjectNode) dataPoint;
     
      // Attempt to get the meta-data;
      MetaData metaData = null;
      JsonNode metaDataNode = dataObject.get(Data.JSON_KEY_METADATA);
      if(metaDataNode != null) {
        metaData = mapper.convertValue(metaDataNode, MetaData.class);
      }
     
      // Attempt to get the schema data.
      JsonNode schemaData = dataObject.get(Data.JSON_KEY_DATA);
     
      // If the data is missing, fail the request.
      if(schemaData == null) {
        throw
          new OmhException(
            "A data point's '" +
              Data.JSON_KEY_DATA +
              "' field is missing.");
      }
     
      // Create and add the point to the set of data.
      dataPoints
        .add(
          schema
            .validateData(
              requestingUser.getUsername(),
              metaData,
              schemaData));
    }
View Full Code Here

                      "Error reading the schema.",
                      e);
                }
               
                return
                  new Schema(
                    id,
                    version,
                    schema,
                    OmhValidationController
                      .VALIDATION_CONTROLLER);
View Full Code Here

                      "Error reading the schema.",
                      e);
                }
               
                return
                  new Schema(
                    id,
                    version,
                    schema,
                    OmhValidationController
                      .VALIDATION_CONTROLLER);
View Full Code Here

TOP

Related Classes of org.openmhealth.reference.domain.Schema

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.