org.startupframework.data.service.EntityServiceBase Maven / Gradle / Ivy
/*
* Copyright 2019-2020 the original author or authors.
*
* 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
*
* https://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 org.startupframework.data.service;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Supplier;
import javax.persistence.metamodel.SingularAttribute;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification;
import org.startupframework.data.entity.Entity;
import org.startupframework.data.entity.OldNewPred;
import org.startupframework.data.repository.EntityRepository;
import org.startupframework.entity.Identifiable;
import org.startupframework.exception.DataNotFoundException;
import org.startupframework.exception.DuplicateDataException;
import org.startupframework.service.ObjectValidatorService;
import lombok.Getter;
/**
* Service base class for EntityBase and inherited.
*
* @author Arq. Jesús Israel Anaya Salazar
*/
public abstract class EntityServiceBase, E extends Entity> extends ObjectValidatorService
implements EntityService {
static final String ASSERT_REPOSITORY = "Should implements repository for %s";
static final String ID_NAME = "id";
@Getter
final R repository;
@Autowired
protected EntityServiceBase(final R repository) {
assert repository != null : String.format(ASSERT_REPOSITORY, this.getClass().getName());
this.repository = repository;
// Anotación para las excepiones y los prefijos
}
protected void existsBy(SingularAttribute attribute, Supplier