// Path: src/main/java/com/github/jasminb/jsonapi/exceptions/InvalidJsonApiResourceException.java
// public class InvalidJsonApiResourceException extends RuntimeException {
// 
//     /**
//      * Creates a new InvalidJsonApiResourceException.
//      */
//     public InvalidJsonApiResourceException() {
//         super("Resource must contain at least one of 'data', 'error' or 'meta' nodes.");
//     }
// 
//     /**
//      * Creates a new InvalidJsonApiResourceException.
//      *
//      * @param errorMessage detail message containing spec for resource that was invalid.
//      */
//     public InvalidJsonApiResourceException(String errorMessage) {
//         super(errorMessage);
//     }
// }
// 
// Path: src/main/java/com/github/jasminb/jsonapi/exceptions/ResourceParseException.java
// public class ResourceParseException extends RuntimeException {
// 	private final Errors errors;
// 
// 	public ResourceParseException(Errors errors) {
// 		super(errors.toString());
// 		this.errors = errors;
// 	}
// 
// 	/**
// 	 * Returns Errors or <code>null</code>
// 	 * @return {@link Errors}
// 	 */
// 	public Errors getErrors() {
// 		return errors;
// 	}
// }
// 
// Path: src/main/java/com/github/jasminb/jsonapi/models/errors/Errors.java
// public class Errors {
// 	private List<Error> errors;
// 
// 	public List<Error> getErrors() {
// 		return errors;
// 	}
// 
// 	public void setErrors(List<Error> errors) {
// 		this.errors = errors;
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return "Errors{" +
// 				"errors=" + (errors != null ? errors : "Undefined") +
// 				'}';
// 	}
// }


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.jasminb.jsonapi.exceptions.InvalidJsonApiResourceException;
import com.github.jasminb.jsonapi.exceptions.ResourceParseException;
import com.github.jasminb.jsonapi.models.errors.Errors;
package com.github.jasminb.jsonapi;


/**
 * Utility methods for validating segments of JSON API resource object.
 *
 * @author jbegic
 */
public class ValidationUtils {

	private ValidationUtils() {
		// Private CTOR
	}

	/**
	 * Ensures document has at least one of 'DATA', 'ERRORS' or 'META' attributes.
	 *
	 * @param resourceNode resource node
	 * @throws ResourceParseException  Maps error attribute into ResourceParseException if present.
	 * @throws InvalidJsonApiResourceException is thrown when node has none of the required attributes.
	 */
	public static void ensureValidDocument(ObjectMapper mapper, JsonNode resourceNode) {
		if (resourceNode == null || resourceNode.isNull()) {
			throw new InvalidJsonApiResourceException();
		}

		boolean hasErrors = resourceNode.hasNonNull(JSONAPISpecConstants.ERRORS);
		boolean hasData = resourceNode.has(JSONAPISpecConstants.DATA);
		boolean hasMeta = resourceNode.has(JSONAPISpecConstants.META);

		if (hasErrors) {
			try {
// Path: src/main/java/com/github/jasminb/jsonapi/exceptions/InvalidJsonApiResourceException.java
// public class InvalidJsonApiResourceException extends RuntimeException {
// 
//     /**
//      * Creates a new InvalidJsonApiResourceException.
//      */
//     public InvalidJsonApiResourceException() {
//         super("Resource must contain at least one of 'data', 'error' or 'meta' nodes.");
//     }
// 
//     /**
//      * Creates a new InvalidJsonApiResourceException.
//      *
//      * @param errorMessage detail message containing spec for resource that was invalid.
//      */
//     public InvalidJsonApiResourceException(String errorMessage) {
//         super(errorMessage);
//     }
// }
// 
// Path: src/main/java/com/github/jasminb/jsonapi/exceptions/ResourceParseException.java
// public class ResourceParseException extends RuntimeException {
// 	private final Errors errors;
// 
// 	public ResourceParseException(Errors errors) {
// 		super(errors.toString());
// 		this.errors = errors;
// 	}
// 
// 	/**
// 	 * Returns Errors or <code>null</code>
// 	 * @return {@link Errors}
// 	 */
// 	public Errors getErrors() {
// 		return errors;
// 	}
// }
// 
// Path: src/main/java/com/github/jasminb/jsonapi/models/errors/Errors.java
// public class Errors {
// 	private List<Error> errors;
// 
// 	public List<Error> getErrors() {
// 		return errors;
// 	}
// 
// 	public void setErrors(List<Error> errors) {
// 		this.errors = errors;
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return "Errors{" +
// 				"errors=" + (errors != null ? errors : "Undefined") +
// 				'}';
// 	}
// }


// Path: src/main/java/com/github/jasminb/jsonapi/ValidationUtils.java
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.jasminb.jsonapi.exceptions.InvalidJsonApiResourceException;
import com.github.jasminb.jsonapi.exceptions.ResourceParseException;
import com.github.jasminb.jsonapi.models.errors.Errors;

package com.github.jasminb.jsonapi;


/**
 * Utility methods for validating segments of JSON API resource object.
 *
 * @author jbegic
 */
public class ValidationUtils {

	private ValidationUtils() {
		// Private CTOR
	}

	/**
	 * Ensures document has at least one of 'DATA', 'ERRORS' or 'META' attributes.
	 *
	 * @param resourceNode resource node
	 * @throws ResourceParseException  Maps error attribute into ResourceParseException if present.
	 * @throws InvalidJsonApiResourceException is thrown when node has none of the required attributes.
	 */
	public static void ensureValidDocument(ObjectMapper mapper, JsonNode resourceNode) {
		if (resourceNode == null || resourceNode.isNull()) {
			throw new InvalidJsonApiResourceException();
		}

		boolean hasErrors = resourceNode.hasNonNull(JSONAPISpecConstants.ERRORS);
		boolean hasData = resourceNode.has(JSONAPISpecConstants.DATA);
		boolean hasMeta = resourceNode.has(JSONAPISpecConstants.META);

		if (hasErrors) {
			try {
				throw new ResourceParseException(ErrorUtils.parseError(mapper, resourceNode, Errors.class));