<commit_before>//
//  PostValidator.java
//  blogwt
//
//  Created by <NAME> (billy1380) on 17 May 2015.
//  Copyright © 2015 WillShex Limited. All rights reserved.
//
package com.willshex.blogwt.server.api.validation;

import com.willshex.blogwt.server.service.post.PostServiceProvider;
import com.willshex.blogwt.shared.api.datatype.Post;
import com.willshex.blogwt.shared.api.validation.ApiError;
import com.willshex.gson.json.service.server.InputValidationException;

/**
 * @author <NAME> (billy1380)
 *
 */
public class PostValidator {
	private static final String type = Post.class.getSimpleName();

	public static Post validate (Post post, String name)
			throws InputValidationException {
		if (post == null)
			ApiValidator.throwServiceError(InputValidationException.class,
					ApiError.InvalidValueNull, type + ": " + name);
		
		return post;
	}

	public static Post lookup (Post post, String name)
			throws InputValidationException {
		if (post == null)
			ApiValidator.throwServiceError(InputValidationException.class,
					ApiError.InvalidValueNull, type + ": " + name);

		boolean isIdLookup = false, isSlugLookup = false;
		if (post.id != null) {
			isIdLookup = true;
		} else if (post.slug != null) {
			isSlugLookup = true;
		}

		if (!(isIdLookup || isSlugLookup))
			ApiValidator.throwServiceError(InputValidationException.class,
					ApiError.DataTypeNoLookup, type + ": " + name);

		Post lookupPost;

		if (isIdLookup) {
			lookupPost = PostServiceProvider.provide().getPost(post.id);
		} else {
			lookupPost = PostServiceProvider.provide().getSlugPost(post.slug);
		}

		if (lookupPost == null)
			ApiValidator.throwServiceError(InputValidationException.class,
					ApiError.DataTypeNotFound, type + ": " + name);

		return lookupPost;
	}

}<commit_msg>added lookup all method to post validator<commit_after>//
//  PostValidator.java
//  blogwt
//
//  Created by <NAME> (billy1380) on 17 May 2015.
//  Copyright © 2015 WillShex Limited. All rights reserved.
//
package com.willshex.blogwt.server.api.validation;

import java.util.ArrayList;
import java.util.List;

import com.willshex.blogwt.server.service.post.PostServiceProvider;
import com.willshex.blogwt.shared.api.datatype.Post;
import com.willshex.blogwt.shared.api.validation.ApiError;
import com.willshex.gson.json.service.server.InputValidationException;

/**
 * @author <NAME> (billy1380)
 *
 */
public class PostValidator {
	private static final String type = Post.class.getSimpleName();

	public static Post validate (Post post, String name)
			throws InputValidationException {
		if (post == null)
			ApiValidator.throwServiceError(InputValidationException.class,
					ApiError.InvalidValueNull, type + ": " + name);

		return post;
	}

	public static Post lookup (Post post, String name)
			throws InputValidationException {
		if (post == null)
			ApiValidator.throwServiceError(InputValidationException.class,
					ApiError.InvalidValueNull, type + ": " + name);

		boolean isIdLookup = false, isSlugLookup = false;
		if (post.id != null) {
			isIdLookup = true;
		} else if (post.slug != null) {
			isSlugLookup = true;
		}

		if (!(isIdLookup || isSlugLookup))
			ApiValidator.throwServiceError(InputValidationException.class,
					ApiError.DataTypeNoLookup, type + ": " + name);

		Post lookupPost;

		if (isIdLookup) {
			lookupPost = PostServiceProvider.provide().getPost(post.id);
		} else {
			lookupPost = PostServiceProvider.provide().getSlugPost(post.slug);
		}

		if (lookupPost == null)
			ApiValidator.throwServiceError(InputValidationException.class,
					ApiError.DataTypeNotFound, type + ": " + name);

		return lookupPost;
	}

	/**
	 * @param posts
	 * @return 
	 * @throws InputValidationException 
	 */
	public static List<Post> lookupAll (List<Post> posts, String name)
			throws InputValidationException {
		if (posts == null)
			ApiValidator.throwServiceError(InputValidationException.class,
					ApiError.InvalidValueNull, type + "[]: " + name);

		List<Post> lookupPosts = new ArrayList<Post>();

		for (Post post : posts) {
			lookupPosts.add(lookup(post, name + "[n]"));
		}

		return lookupPosts;
	}

}
{'fraction_non_alphanumeric': 0.11905916585838991, 'fraction_numerical': 0.008729388942774006, 'mean_word_length': 4.136986301369863, 'pattern_counts': {'":': 8, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3142699', 'n_tokens_mistral': 1433, 'n_tokens_neox': 1258, 'n_words': 281}