ca.gc.aafc.dina.repository.external.ExternalRepository Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dina-base-api Show documentation
Show all versions of dina-base-api Show documentation
Base DINA API package for Java built on SpringBoot and Crnk
package ca.gc.aafc.dina.repository.external;
import ca.gc.aafc.dina.dto.ExternalRelationDto;
import io.crnk.core.exception.MethodNotAllowedException;
import io.crnk.core.queryspec.QuerySpec;
import io.crnk.core.repository.UntypedResourceRepository;
import io.crnk.core.resource.annotations.JsonApiExposed;
import io.crnk.core.resource.list.ResourceList;
import java.util.Collection;
/**
* Internal Repository required to mimic relations for ExternalRelationDto's usage. External
* relations are not backed by a real resource.
*/
@JsonApiExposed(false)
public class ExternalRepository implements UntypedResourceRepository {
private final String resourceType;
public ExternalRepository(String resourceType) {
this.resourceType = resourceType;
}
@Override
public ExternalRelationDto findOne(String id, QuerySpec querySpec) {
return ExternalRelationDto.builder().type(resourceType).id(id).build();
}
@Override
public ResourceList findAll(QuerySpec querySpec) {
throw new MethodNotAllowedException("External Types only use findOne");
}
@Override
public ResourceList findAll(
Collection collection, QuerySpec querySpec
) {
throw new MethodNotAllowedException("External Types only use findOne");
}
@Override
public S save(S s) {
throw new MethodNotAllowedException("External Types cannot be patched");
}
@Override
public S create(S s) {
throw new MethodNotAllowedException("External Types cannot be created");
}
@Override
public void delete(String serializable) {
throw new MethodNotAllowedException("External Types cannot be deleted");
}
@Override
public String getResourceType() {
return this.resourceType;
}
@Override
public Class getResourceClass() {
return ExternalRelationDto.class;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy