// Path: src/main/java/com/google/adwords/scripts/solutions/linkchecker/service/JobsCleanupService.java
// public class JobsCleanupService {
//   public static final int OLD_JOB_CUTOFF_DAYS = 30;
// 
//   private final BatchOperationService batchOperationService;
//   private final Datastore datastore;
// 
//   public static final String INDEX_BUILD_PATH = "/cron/jobscleanup";
// 
//   @Inject
//   public JobsCleanupService(
//       BatchOperationService batchOperationService, Datastore datastore) {
//     this.batchOperationService = batchOperationService;
//     this.datastore = datastore;
//   }
// 
//   /**
//    * Deletes {@code BatchOperation}s that were created before then cutoff number of days ago.
//    */
//   public void cleanup() {
//     Calendar cal = Calendar.getInstance();
//     cal.setTime(new Date());
//     cal.add(Calendar.DATE, -OLD_JOB_CUTOFF_DAYS);
//     Date cutoffDate = cal.getTime();
// 
//     List<BatchOperation> oldOps = batchOperationService.listHistoricBatchOperations(cutoffDate);
//     for (BatchOperation oldOp : oldOps) {
//       datastore.deleteBatchOperation(oldOp.getAccountId(), oldOp.getBatchId());
//     }
//   }
// }
// 
// Path: src/main/java/com/google/adwords/scripts/solutions/linkchecker/service/SharedKeyService.java
// public class SharedKeyService {
//   Datastore datastore;
//   
//   @Inject
//   public SharedKeyService(Datastore datastore) {
//     this.datastore = datastore;
//   }
//   
//   public SharedKey getKey() {
//     SharedKey key;
//     try {
//       key = datastore.getKey();
//       if (key == null) {
//         key = datastore.createKey();
//       }
//     } catch (NotFoundException e) {
//       key = datastore.createKey();
//     }
//     return key;
//   }
// }


import com.google.adwords.scripts.solutions.linkchecker.service.JobsCleanupService;
import com.google.adwords.scripts.solutions.linkchecker.service.SharedKeyService;
import com.google.inject.Inject;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
// Copyright 2017, Google Inc. All Rights Reserved.
//
// 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 com.google.adwords.scripts.solutions.linkchecker;


/**
 * Servlet to respond to the requests from the AppEngine cron and clean up old BatchOperation
 * entries.
 */
public class CronServlet extends HttpServlet {
  private final JobsCleanupService jobsCleanupService;

  @Inject
// Path: src/main/java/com/google/adwords/scripts/solutions/linkchecker/service/JobsCleanupService.java
// public class JobsCleanupService {
//   public static final int OLD_JOB_CUTOFF_DAYS = 30;
// 
//   private final BatchOperationService batchOperationService;
//   private final Datastore datastore;
// 
//   public static final String INDEX_BUILD_PATH = "/cron/jobscleanup";
// 
//   @Inject
//   public JobsCleanupService(
//       BatchOperationService batchOperationService, Datastore datastore) {
//     this.batchOperationService = batchOperationService;
//     this.datastore = datastore;
//   }
// 
//   /**
//    * Deletes {@code BatchOperation}s that were created before then cutoff number of days ago.
//    */
//   public void cleanup() {
//     Calendar cal = Calendar.getInstance();
//     cal.setTime(new Date());
//     cal.add(Calendar.DATE, -OLD_JOB_CUTOFF_DAYS);
//     Date cutoffDate = cal.getTime();
// 
//     List<BatchOperation> oldOps = batchOperationService.listHistoricBatchOperations(cutoffDate);
//     for (BatchOperation oldOp : oldOps) {
//       datastore.deleteBatchOperation(oldOp.getAccountId(), oldOp.getBatchId());
//     }
//   }
// }
// 
// Path: src/main/java/com/google/adwords/scripts/solutions/linkchecker/service/SharedKeyService.java
// public class SharedKeyService {
//   Datastore datastore;
//   
//   @Inject
//   public SharedKeyService(Datastore datastore) {
//     this.datastore = datastore;
//   }
//   
//   public SharedKey getKey() {
//     SharedKey key;
//     try {
//       key = datastore.getKey();
//       if (key == null) {
//         key = datastore.createKey();
//       }
//     } catch (NotFoundException e) {
//       key = datastore.createKey();
//     }
//     return key;
//   }
// }


// Path: src/main/java/com/google/adwords/scripts/solutions/linkchecker/CronServlet.java
import com.google.adwords.scripts.solutions.linkchecker.service.JobsCleanupService;
import com.google.adwords.scripts.solutions.linkchecker.service.SharedKeyService;
import com.google.inject.Inject;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

// Copyright 2017, Google Inc. All Rights Reserved.
//
// 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 com.google.adwords.scripts.solutions.linkchecker;


/**
 * Servlet to respond to the requests from the AppEngine cron and clean up old BatchOperation
 * entries.
 */
public class CronServlet extends HttpServlet {
  private final JobsCleanupService jobsCleanupService;

  @Inject
  public CronServlet(JobsCleanupService jobsCleanupService, SharedKeyService sharedKeyService) {