// Path: src/main/java/com/quantumsoft/qupathcloud/dao/Constants.java
// public static final String DATASETS = "/datasets/";
// 
// Path: src/main/java/com/quantumsoft/qupathcloud/dao/Constants.java
// public static final String DICOM_STORES = "/dicomStores/";
// 
// Path: src/main/java/com/quantumsoft/qupathcloud/dao/Constants.java
// public static final String DICOM_WEB = "/dicomWeb";
// 
// Path: src/main/java/com/quantumsoft/qupathcloud/dao/Constants.java
// public static final String INSTANCES = "/instances/";
// 
// Path: src/main/java/com/quantumsoft/qupathcloud/dao/Constants.java
// public static final String LOCATIONS = "/locations/";
// 
// Path: src/main/java/com/quantumsoft/qupathcloud/dao/Constants.java
// public static final String PROJECTS = "/projects/";
// 
// Path: src/main/java/com/quantumsoft/qupathcloud/dao/Constants.java
// public static final String SERIES = "/series/";
// 
// Path: src/main/java/com/quantumsoft/qupathcloud/dao/Constants.java
// public static final String STAGE = "/v1beta1";
// 
// Path: src/main/java/com/quantumsoft/qupathcloud/dao/Constants.java
// public static final String STUDIES = "/studies/";
// 
// Path: src/main/java/com/quantumsoft/qupathcloud/exception/QuPathCloudException.java
// public class QuPathCloudException extends Exception {
// 
//   /**
//    * Instantiates a new QuPath cloud exception.
//    *
//    * @param message the message
//    */
//   public QuPathCloudException(String message) {
//     super(message);
//   }
// 
//   /**
//    * Instantiates a new QuPath cloud exception.
//    *
//    * @param e the exception
//    */
//   public QuPathCloudException(Throwable e) {
//     super(e);
//   }
// }


import static com.quantumsoft.qupathcloud.dao.Constants.DATASETS;
import static com.quantumsoft.qupathcloud.dao.Constants.DICOM_STORES;
import static com.quantumsoft.qupathcloud.dao.Constants.DICOM_WEB;
import static com.quantumsoft.qupathcloud.dao.Constants.INSTANCES;
import static com.quantumsoft.qupathcloud.dao.Constants.LOCATIONS;
import static com.quantumsoft.qupathcloud.dao.Constants.PROJECTS;
import static com.quantumsoft.qupathcloud.dao.Constants.SERIES;
import static com.quantumsoft.qupathcloud.dao.Constants.STAGE;
import static com.quantumsoft.qupathcloud.dao.Constants.STUDIES;
import com.quantumsoft.qupathcloud.exception.QuPathCloudException;
// Copyright (C) 2019 Google LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

package com.quantumsoft.qupathcloud.dao.spec;



/**
 * InstancesPathBuilder builds a path to access Instances in the specified Project, Location,
 * Dataset, DICOM Store, Study and Series. If the Study and Series are null then the path will be
 * built for all Instances in a chosen Project, Location, Dataset, and DICOM Store.
 */
public class InstancesPathBuilder implements PathBuilder {

  private QueryBuilder queryBuilder;

  /**
   * Instantiates a new Instances path builder.
   *
   * @param queryBuilder the query builder with parameters
   */
  public InstancesPathBuilder(QueryBuilder queryBuilder) {
    this.queryBuilder = queryBuilder;
  }

  @Override
  public String toPath() throws QuPathCloudException {
    if (queryBuilder.getLocationId() == null) {
      throw new QuPathCloudException("Location must not be null!");
    }
    if (queryBuilder.getDatasetId() == null) {
      throw new QuPathCloudException("Dataset must not be null!");
    }
    if (queryBuilder.getDicomStoreId() == null) {
      throw new QuPathCloudException("DicomStore must not be null!");
    }
    String studyId = queryBuilder.getStudyId();
    String seriesId = queryBuilder.getSeriesId();
    if (studyId != null && seriesId != null) {
      return STAGE + PROJECTS + queryBuilder.getProjectId() + LOCATIONS + queryBuilder
          .getLocationId() + DATASETS + queryBuilder.getDatasetId() + DICOM_STORES +
          queryBuilder.getDicomStoreId() + DICOM_WEB + STUDIES + studyId + SERIES +
          seriesId + INSTANCES;
    } else {
      return STAGE + PROJECTS + queryBuilder.getProjectId() + LOCATIONS + queryBuilder
// Path: src/main/java/com/quantumsoft/qupathcloud/dao/Constants.java
// public static final String DATASETS = "/datasets/";
// 
// Path: src/main/java/com/quantumsoft/qupathcloud/dao/Constants.java
// public static final String DICOM_STORES = "/dicomStores/";
// 
// Path: src/main/java/com/quantumsoft/qupathcloud/dao/Constants.java
// public static final String DICOM_WEB = "/dicomWeb";
// 
// Path: src/main/java/com/quantumsoft/qupathcloud/dao/Constants.java
// public static final String INSTANCES = "/instances/";
// 
// Path: src/main/java/com/quantumsoft/qupathcloud/dao/Constants.java
// public static final String LOCATIONS = "/locations/";
// 
// Path: src/main/java/com/quantumsoft/qupathcloud/dao/Constants.java
// public static final String PROJECTS = "/projects/";
// 
// Path: src/main/java/com/quantumsoft/qupathcloud/dao/Constants.java
// public static final String SERIES = "/series/";
// 
// Path: src/main/java/com/quantumsoft/qupathcloud/dao/Constants.java
// public static final String STAGE = "/v1beta1";
// 
// Path: src/main/java/com/quantumsoft/qupathcloud/dao/Constants.java
// public static final String STUDIES = "/studies/";
// 
// Path: src/main/java/com/quantumsoft/qupathcloud/exception/QuPathCloudException.java
// public class QuPathCloudException extends Exception {
// 
//   /**
//    * Instantiates a new QuPath cloud exception.
//    *
//    * @param message the message
//    */
//   public QuPathCloudException(String message) {
//     super(message);
//   }
// 
//   /**
//    * Instantiates a new QuPath cloud exception.
//    *
//    * @param e the exception
//    */
//   public QuPathCloudException(Throwable e) {
//     super(e);
//   }
// }


// Path: src/main/java/com/quantumsoft/qupathcloud/dao/spec/InstancesPathBuilder.java
import static com.quantumsoft.qupathcloud.dao.Constants.DATASETS;
import static com.quantumsoft.qupathcloud.dao.Constants.DICOM_STORES;
import static com.quantumsoft.qupathcloud.dao.Constants.DICOM_WEB;
import static com.quantumsoft.qupathcloud.dao.Constants.INSTANCES;
import static com.quantumsoft.qupathcloud.dao.Constants.LOCATIONS;
import static com.quantumsoft.qupathcloud.dao.Constants.PROJECTS;
import static com.quantumsoft.qupathcloud.dao.Constants.SERIES;
import static com.quantumsoft.qupathcloud.dao.Constants.STAGE;
import static com.quantumsoft.qupathcloud.dao.Constants.STUDIES;
import com.quantumsoft.qupathcloud.exception.QuPathCloudException;

// Copyright (C) 2019 Google LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

package com.quantumsoft.qupathcloud.dao.spec;



/**
 * InstancesPathBuilder builds a path to access Instances in the specified Project, Location,
 * Dataset, DICOM Store, Study and Series. If the Study and Series are null then the path will be
 * built for all Instances in a chosen Project, Location, Dataset, and DICOM Store.
 */
public class InstancesPathBuilder implements PathBuilder {

  private QueryBuilder queryBuilder;

  /**
   * Instantiates a new Instances path builder.
   *
   * @param queryBuilder the query builder with parameters
   */
  public InstancesPathBuilder(QueryBuilder queryBuilder) {
    this.queryBuilder = queryBuilder;
  }

  @Override
  public String toPath() throws QuPathCloudException {
    if (queryBuilder.getLocationId() == null) {
      throw new QuPathCloudException("Location must not be null!");
    }
    if (queryBuilder.getDatasetId() == null) {
      throw new QuPathCloudException("Dataset must not be null!");
    }
    if (queryBuilder.getDicomStoreId() == null) {
      throw new QuPathCloudException("DicomStore must not be null!");
    }
    String studyId = queryBuilder.getStudyId();
    String seriesId = queryBuilder.getSeriesId();
    if (studyId != null && seriesId != null) {
      return STAGE + PROJECTS + queryBuilder.getProjectId() + LOCATIONS + queryBuilder
          .getLocationId() + DATASETS + queryBuilder.getDatasetId() + DICOM_STORES +
          queryBuilder.getDicomStoreId() + DICOM_WEB + STUDIES + studyId + SERIES +
          seriesId + INSTANCES;
    } else {
      return STAGE + PROJECTS + queryBuilder.getProjectId() + LOCATIONS + queryBuilder
          .getLocationId() + DATASETS + queryBuilder.getDatasetId() + DICOM_STORES +