/*
 * Copyright 2019 Google LLC. 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.
 *
 * Any software provided by Google hereunder is distributed “AS IS”,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, and is not intended for production use.
 *
 */

package com.google.gcs.sdrs.resource;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import com.google.gcs.sdrs.dao.Dao;
import com.google.gcs.sdrs.dao.SingletonDao;
import com.google.gcs.sdrs.dao.model.RetentionJob;
import com.google.gcs.sdrs.dao.model.RetentionRule;
import com.google.gcs.sdrs.rule.RuleExecutor;
import com.google.gcs.sdrs.rule.StsRuleExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
 * Root resource (exposed at "myresource" path)
 *
 * @deprecated
 */
@Path("/myresource")
public class MyResource {

  static final private Logger logger = LoggerFactory.getLogger(MyResource.class);

  /**
   * Method handling HTTP GET requests. The returned object will be sent
   * to the client as "text/plain" media type.
   *
   * @return String that will be returned as a text/plain response.
   */
  @GET
  @Produces(MediaType.TEXT_PLAIN)
  public String getIt() {
    logger.debug("Get Got Gotten");

    // The following is test code to execute the STS utility. This assumes a retention rule
    // with ID = 1 exists in the database
    Dao<RetentionRule, Integer> ruleDao = SingletonDao.getRetentionRuleDao();

    RetentionRule rule = ruleDao.findById(1);

    try{
      RuleExecutor executor = StsRuleExecutor.getInstance();
      RetentionJob job = executor.executeDatasetRule(rule);
    } catch (IOException ex) {
      logger.error("Couldn't submit rule for execution: " + ex.getMessage());
    }

    return "Got it good!";
  }
}

@@ -1056,16 +1056,77 @@
 ionJob;%0A
+import com.google.gcs.sdrs.dao.model.RetentionJobValidation;%0A
 import c
@@ -1247,28 +1247,125 @@
 rs.rule.
-StsRuleExecu
+RuleValidator;%0Aimport com.google.gcs.sdrs.rule.StsRuleExecutor;%0Aimport com.google.gcs.sdrs.rule.StsRuleValida
 tor;%0Aimp
@@ -2096,16 +2096,18 @@
 atabase%0A
+//
     Dao%3C
@@ -2173,24 +2173,26 @@
 RuleDao();%0A%0A
+//
     Retentio
@@ -2222,24 +2222,146 @@
 ndById(1);%0A%0A
+    Dao%3CRetentionJob, Integer%3E jobDao = SingletonDao.getRetentionJobDao();%0A%0A    RetentionJob job = jobDao.findById(1);%0A%0A//
     try%7B%0A   
@@ -2357,16 +2357,18 @@
    try%7B%0A
+//
       Ru
@@ -2420,16 +2420,18 @@
 ance();%0A
+//
       Re
@@ -2482,16 +2482,159 @@
 (rule);%0A
+      RuleValidator validator = StsRuleValidator.getInstance();%0A      RetentionJobValidation response = validator.validateRetentionJob(job);%0A//
     %7D ca
@@ -2652,24 +2652,26 @@
 ption ex) %7B%0A
+//
       logger
@@ -2736,16 +2736,18 @@
 age());%0A
+//
     %7D%0A%0A 

Update MyResource.java