// Path: try_java_ee7-web/src/main/java/enterprisegeeks/rest/dto/NewChat.java
// public class NewChat {
//   
//     @NotNull(message = "{required}")
//     public long roomId;
//     
//     @NotNull(message = "{required}")
//     @Size(message = "{required}", min = 1)
//     public String content;
// }
// 
// Path: try_java_ee7-web/src/main/java/enterprisegeeks/service/Service.java
// public interface Service{
//     
//     
//     public boolean registerAccount(Account accout);
//     
//     public Account findAccountByName(String name);
//     
//     /** ログイン用トークン発行 */
//     public String publishToken(Account account);
//     
//     /** チャットルーム一覧 */
//     public List<Room> allRooms();
//     
//     /** チャットルームのチャット一覧を取得 */
//     public List<Chat> findChatByRoom(Room room, Timestamp from);
//     
//     public void addChat(Chat chat);
//     
//     public Account getAccountByToken(String token);
//     
//     
// }


import enterprisegeeks.rest.dto.NewChat;
import enterprisegeeks.service.Service;
import enterprisegeeks.util.ScheduledExecutor;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.enterprise.concurrent.LastExecution;
import javax.enterprise.concurrent.ManagedScheduledExecutorService;
import javax.enterprise.concurrent.Trigger;
import javax.inject.Inject;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
            public Date getNextRunTime(LastExecution le, Date date) {
                if (le == null) {
                    // 初回実行時
                    Calendar cal = Calendar.getInstance();
                    cal.setTime(date);
                    cal.add(Calendar.HOUR, 1);
                    cal.set(Calendar.SECOND, 0);
                    cal.set(Calendar.MINUTE, 0);
                    cal.set(Calendar.MILLISECOND, 0);
                    logger.fine(() -> "bot first execution at " + cal.getTime());
                    return cal.getTime();
                }
                // 前回実行時の1時間後
                Date next =  new Date(le.getScheduledStart().getTime() + 3600 * 1000);
                logger.fine(() -> "bot next execution at " + next);
                return next;
            }

            @Override
            public boolean skipRun(LastExecution le, Date date) {
                return false;
            }
        };
        
        Runnable command = () -> {
            String now = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"));
            roomIds.forEach(roomId -> {
                NewChat nc = new NewChat();
                nc.roomId = roomId;
                nc.content = "今は" + now + "です。";
// Path: try_java_ee7-web/src/main/java/enterprisegeeks/rest/dto/NewChat.java
// public class NewChat {
//   
//     @NotNull(message = "{required}")
//     public long roomId;
//     
//     @NotNull(message = "{required}")
//     @Size(message = "{required}", min = 1)
//     public String content;
// }
// 
// Path: try_java_ee7-web/src/main/java/enterprisegeeks/service/Service.java
// public interface Service{
//     
//     
//     public boolean registerAccount(Account accout);
//     
//     public Account findAccountByName(String name);
//     
//     /** ログイン用トークン発行 */
//     public String publishToken(Account account);
//     
//     /** チャットルーム一覧 */
//     public List<Room> allRooms();
//     
//     /** チャットルームのチャット一覧を取得 */
//     public List<Chat> findChatByRoom(Room room, Timestamp from);
//     
//     public void addChat(Chat chat);
//     
//     public Account getAccountByToken(String token);
//     
//     
// }


// Path: try_java_ee7-web/src/main/java/enterprisegeeks/bot/NotifyBot.java
import enterprisegeeks.rest.dto.NewChat;
import enterprisegeeks.service.Service;
import enterprisegeeks.util.ScheduledExecutor;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.enterprise.concurrent.LastExecution;
import javax.enterprise.concurrent.ManagedScheduledExecutorService;
import javax.enterprise.concurrent.Trigger;
import javax.inject.Inject;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;

            public Date getNextRunTime(LastExecution le, Date date) {
                if (le == null) {
                    // 初回実行時
                    Calendar cal = Calendar.getInstance();
                    cal.setTime(date);
                    cal.add(Calendar.HOUR, 1);
                    cal.set(Calendar.SECOND, 0);
                    cal.set(Calendar.MINUTE, 0);
                    cal.set(Calendar.MILLISECOND, 0);
                    logger.fine(() -> "bot first execution at " + cal.getTime());
                    return cal.getTime();
                }
                // 前回実行時の1時間後
                Date next =  new Date(le.getScheduledStart().getTime() + 3600 * 1000);
                logger.fine(() -> "bot next execution at " + next);
                return next;
            }

            @Override
            public boolean skipRun(LastExecution le, Date date) {
                return false;
            }
        };
        
        Runnable command = () -> {
            String now = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"));
            roomIds.forEach(roomId -> {
                NewChat nc = new NewChat();
                nc.roomId = roomId;
                nc.content = "今は" + now + "です。";
                Client c = ClientBuilder.newClient().register(NewChat.class);