// Path: frostillicus-blog/frostillicus-blog-shared/src/main/java/model/PostRepository.java
// @RepositoryProvider(AppDatabaseDef.STORE_POSTS)
// public interface PostRepository extends DarwinoRepository<Post, String> {
// 	@StoredCursor("FindPost")
// 	Optional<Post> findPost(@Param("key") String key);
// 
// 	@JSQL("select unid from posts where $.postIdInt::int=:postIdInt")
// 	Optional<Post> findByPostIdInt(@Param("postIdInt") int postIdInt);
// 
// 	@StoredCursor("PostsByTag")
// 	List<Post> findByTag(@Param("tag") String tag);
// 
// 	@StoredCursor("PostsByMonth")
// 	List<Post> findByMonth(@Param("monthQuery") String monthQuery);
// 
// 	@Search(orderBy="posted desc")
// 	List<Post> search(String query);
// 
// 	@JSQL("select unid from posts where $.form='Post' order by $.posted desc limit 10")
// 	List<Post> homeList();
// 
// 	@JSQL("select unid from posts where $.form='Post' order by $.posted desc")
// 	List<Post> homeList(@Param("skip") int skip, @Param("limit") int limit);
// 
// 	@JSQL("select unid from posts where $.form='Post' and $.thread=:thread order by $.posted")
// 	List<Post> findByThread(@Param("thread") String thread);
// 
// 	Optional<Post> findByName(String name);
// }
// 
// Path: frostillicus-blog/frostillicus-blog-shared/src/main/java/model/util/PostUtil.java
// public enum PostUtil {
//     ;
//     public static final int PAGE_LENGTH = 10;
// 
//     public static int getPostCount() throws JsonException {
//         Database database = CDI.current().select(Database.class).get();
//         Store store = database.getStore(AppDatabaseDef.STORE_POSTS);
//         return store.openCursor()
//                 .query(JsonObject.of("form", Post.class.getSimpleName())) //$NON-NLS-1$
//                 .count();
//     }
// 
//     public static Collection<String> getPostMonths() throws JsonException {
//         Collection<String> months = new TreeSet<>();
// 
//         Database database = CDI.current().select(Database.class).get();
//         Store store = database.getStore(AppDatabaseDef.STORE_POSTS);
//         store.openCursor()
//                 .query(JsonObject.of("form", Post.class.getSimpleName())) //$NON-NLS-1$
//                 .extract(JsonObject.of("posted", "posted")) //$NON-NLS-1$ //$NON-NLS-2$
//                 .find(entry -> {
//                     String posted = entry.getString("posted"); //$NON-NLS-1$
//                     if(posted != null && posted.length() >= 7) {
//                         months.add(posted.substring(0, 7));
//                     }
//                     return true;
//                 });
// 
//         return months;
//     }
// 
//     public static Post createPost() {
//         Post post = new Post();
//         post.setPosted(OffsetDateTime.now());
//         post.setPostId(UUID.randomUUID().toString());
// 
//         // It's not pretty, but it's CLOSER to replication-safe
//         Random random = new Random();
//         PostRepository posts = CDI.current().select(PostRepository.class).get();
//         int postIdInt;
//         do {
//             postIdInt = random.nextInt();
//         } while(posts.findByPostIdInt(postIdInt).isPresent());
//         post.setPostIdInt(postIdInt);
// 
//         return post;
//     }
// 
//     public static Collection<String> getCategories() throws JsonException {
//         Database database = CDI.current().select(Database.class).get();
//         JsonArray tags = (JsonArray)database.getStore(AppDatabaseDef.STORE_POSTS).getTags(Integer.MAX_VALUE, true);
//         return tags.stream()
//                 .map(JsonObject.class::cast)
//                 .map(tag -> tag.getAsString("name")) //$NON-NLS-1$
//                 .map(StringUtil::toString)
//                 .collect(Collectors.toList());
//     }
// 
//     public static int parseStartParam(final String startParam) {
//         int start;
//         if(StringUtil.isNotEmpty(startParam)) {
//             try {
//                 start = Integer.parseInt(startParam);
//             } catch(NumberFormatException e) {
//                 start = -1;
//             }
//         } else {
//             start = -1;
//         }
//         return start;
//     }
// 
//     /**
//      * Extracts the common name from the provided distinguished name, or returns
//      * the original value if the argument is not a valid DN.
//      *
//      * @param dn the LDAP-format distinguished name
//      * @return the common name component
//      * @since 2.2.0
//      */
//     public static String toCn(final String dn) {
// 		if(StringUtil.isNotEmpty(dn)) {
// 			try {
// 				LdapName name = new LdapName(dn);
// 				for(int i = name.size()-1; i >= 0; i--) {
// 					String bit = name.get(i);
// 					if(bit.toLowerCase().startsWith("cn=")) { //$NON-NLS-1$
// 						return bit.substring(3);
// 					}
// 				}
// 			} catch(InvalidNameException e) {
// 				return dn;
// 			}
// 		}
// 		return StringUtil.EMPTY_STRING;
//     }
// }


import static model.util.PostUtil.PAGE_LENGTH;
import javax.inject.Inject;
import javax.mvc.Models;
import com.darwino.commons.json.JsonException;
import model.PostRepository;
import model.util.PostUtil;
/*
 * Copyright © 2012-2020 Jesse Gallagher
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package controller;





public abstract class AbstractPostListController {
    @Inject
    Models models;

    @Inject
// Path: frostillicus-blog/frostillicus-blog-shared/src/main/java/model/PostRepository.java
// @RepositoryProvider(AppDatabaseDef.STORE_POSTS)
// public interface PostRepository extends DarwinoRepository<Post, String> {
// 	@StoredCursor("FindPost")
// 	Optional<Post> findPost(@Param("key") String key);
// 
// 	@JSQL("select unid from posts where $.postIdInt::int=:postIdInt")
// 	Optional<Post> findByPostIdInt(@Param("postIdInt") int postIdInt);
// 
// 	@StoredCursor("PostsByTag")
// 	List<Post> findByTag(@Param("tag") String tag);
// 
// 	@StoredCursor("PostsByMonth")
// 	List<Post> findByMonth(@Param("monthQuery") String monthQuery);
// 
// 	@Search(orderBy="posted desc")
// 	List<Post> search(String query);
// 
// 	@JSQL("select unid from posts where $.form='Post' order by $.posted desc limit 10")
// 	List<Post> homeList();
// 
// 	@JSQL("select unid from posts where $.form='Post' order by $.posted desc")
// 	List<Post> homeList(@Param("skip") int skip, @Param("limit") int limit);
// 
// 	@JSQL("select unid from posts where $.form='Post' and $.thread=:thread order by $.posted")
// 	List<Post> findByThread(@Param("thread") String thread);
// 
// 	Optional<Post> findByName(String name);
// }
// 
// Path: frostillicus-blog/frostillicus-blog-shared/src/main/java/model/util/PostUtil.java
// public enum PostUtil {
//     ;
//     public static final int PAGE_LENGTH = 10;
// 
//     public static int getPostCount() throws JsonException {
//         Database database = CDI.current().select(Database.class).get();
//         Store store = database.getStore(AppDatabaseDef.STORE_POSTS);
//         return store.openCursor()
//                 .query(JsonObject.of("form", Post.class.getSimpleName())) //$NON-NLS-1$
//                 .count();
//     }
// 
//     public static Collection<String> getPostMonths() throws JsonException {
//         Collection<String> months = new TreeSet<>();
// 
//         Database database = CDI.current().select(Database.class).get();
//         Store store = database.getStore(AppDatabaseDef.STORE_POSTS);
//         store.openCursor()
//                 .query(JsonObject.of("form", Post.class.getSimpleName())) //$NON-NLS-1$
//                 .extract(JsonObject.of("posted", "posted")) //$NON-NLS-1$ //$NON-NLS-2$
//                 .find(entry -> {
//                     String posted = entry.getString("posted"); //$NON-NLS-1$
//                     if(posted != null && posted.length() >= 7) {
//                         months.add(posted.substring(0, 7));
//                     }
//                     return true;
//                 });
// 
//         return months;
//     }
// 
//     public static Post createPost() {
//         Post post = new Post();
//         post.setPosted(OffsetDateTime.now());
//         post.setPostId(UUID.randomUUID().toString());
// 
//         // It's not pretty, but it's CLOSER to replication-safe
//         Random random = new Random();
//         PostRepository posts = CDI.current().select(PostRepository.class).get();
//         int postIdInt;
//         do {
//             postIdInt = random.nextInt();
//         } while(posts.findByPostIdInt(postIdInt).isPresent());
//         post.setPostIdInt(postIdInt);
// 
//         return post;
//     }
// 
//     public static Collection<String> getCategories() throws JsonException {
//         Database database = CDI.current().select(Database.class).get();
//         JsonArray tags = (JsonArray)database.getStore(AppDatabaseDef.STORE_POSTS).getTags(Integer.MAX_VALUE, true);
//         return tags.stream()
//                 .map(JsonObject.class::cast)
//                 .map(tag -> tag.getAsString("name")) //$NON-NLS-1$
//                 .map(StringUtil::toString)
//                 .collect(Collectors.toList());
//     }
// 
//     public static int parseStartParam(final String startParam) {
//         int start;
//         if(StringUtil.isNotEmpty(startParam)) {
//             try {
//                 start = Integer.parseInt(startParam);
//             } catch(NumberFormatException e) {
//                 start = -1;
//             }
//         } else {
//             start = -1;
//         }
//         return start;
//     }
// 
//     /**
//      * Extracts the common name from the provided distinguished name, or returns
//      * the original value if the argument is not a valid DN.
//      *
//      * @param dn the LDAP-format distinguished name
//      * @return the common name component
//      * @since 2.2.0
//      */
//     public static String toCn(final String dn) {
// 		if(StringUtil.isNotEmpty(dn)) {
// 			try {
// 				LdapName name = new LdapName(dn);
// 				for(int i = name.size()-1; i >= 0; i--) {
// 					String bit = name.get(i);
// 					if(bit.toLowerCase().startsWith("cn=")) { //$NON-NLS-1$
// 						return bit.substring(3);
// 					}
// 				}
// 			} catch(InvalidNameException e) {
// 				return dn;
// 			}
// 		}
// 		return StringUtil.EMPTY_STRING;
//     }
// }


// Path: frostillicus-blog/frostillicus-blog-j2ee/src/main/java/controller/AbstractPostListController.java
import static model.util.PostUtil.PAGE_LENGTH;
import javax.inject.Inject;
import javax.mvc.Models;
import com.darwino.commons.json.JsonException;
import model.PostRepository;
import model.util.PostUtil;

/*
 * Copyright © 2012-2020 Jesse Gallagher
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package controller;





public abstract class AbstractPostListController {
    @Inject
    Models models;

    @Inject
    PostRepository posts;