All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ca.gc.aafc.dina.repository.ReadOnlyDinaRepository Maven / Gradle / Ivy

There is a newer version: 0.132
Show newest version
package ca.gc.aafc.dina.repository;

import ca.gc.aafc.dina.entity.DinaEntity;
import ca.gc.aafc.dina.filter.DinaFilterResolver;
import ca.gc.aafc.dina.mapper.DinaMapper;
import ca.gc.aafc.dina.security.auth.ReadOnlyAuthorizationService;
import ca.gc.aafc.dina.service.DinaService;
import io.crnk.core.exception.MethodNotAllowedException;
import org.springframework.boot.info.BuildProperties;

import java.io.Serializable;
import java.util.Optional;

/**
 * Read-only version of {@link DinaRepository}.
 * create, save and delete will throw a {@link MethodNotAllowedException}.
 * Authorization and auditing services is disabled.
 * @param 
 * @param 
 */
public class ReadOnlyDinaRepository extends DinaRepository {
  public ReadOnlyDinaRepository(
    DinaService dinaService,
    DinaMapper dinaMapper,
    Class resourceClass,
    Class entityClass,
    DinaFilterResolver filterResolver,
    BuildProperties buildProperties
  ) {
    super(
      dinaService,
      new ReadOnlyAuthorizationService(),
      Optional.empty(),
      dinaMapper,
      resourceClass,
      entityClass,
      filterResolver,
      null,
      buildProperties, null);
  }

  /**
   * Throws {@link MethodNotAllowedException}
   * Create not allowed on read-only
   * @param resource
   * @param 
   * @return
   */
  @Override
  public  S create(S resource) {
    throw new MethodNotAllowedException("POST");
  }

  /**
   * Throws {@link MethodNotAllowedException}
   * Save not allowed on read-only
   * @param resource
   * @param 
   * @return
   */
  @Override
  public  S save(S resource) {
    throw new MethodNotAllowedException("PUT/PATCH");
  }

  /**
   * Throws {@link MethodNotAllowedException}
   * Delete not allowed on read-only
   * @param id
   */
  @Override
  public void delete(Serializable id) {
    throw new MethodNotAllowedException("DELETE");
  }
}