Search in sources :

Example 11 with EntityNotFoundException

use of javax.persistence.EntityNotFoundException in project OpenAttestation by OpenAttestation.

the class TblEventTypeJpaController method destroy.

public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblEventType tblEventType;
        try {
            tblEventType = em.getReference(TblEventType.class, id);
            tblEventType.getId();
        } catch (EntityNotFoundException enfe) {
            throw new NonexistentEntityException("The tblEventType with id " + id + " no longer exists.", enfe);
        }
        List<String> illegalOrphanMessages = null;
        Collection<TblModuleManifest> tblModuleManifestCollectionOrphanCheck = tblEventType.getTblModuleManifestCollection();
        for (TblModuleManifest tblModuleManifestCollectionOrphanCheckTblModuleManifest : tblModuleManifestCollectionOrphanCheck) {
            if (illegalOrphanMessages == null) {
                illegalOrphanMessages = new ArrayList<String>();
            }
            illegalOrphanMessages.add("This TblEventType (" + tblEventType + ") cannot be destroyed since the TblModuleManifest " + tblModuleManifestCollectionOrphanCheckTblModuleManifest + " in its tblModuleManifestCollection field has a non-nullable eventID field.");
        }
        if (illegalOrphanMessages != null) {
            throw new IllegalOrphanException(illegalOrphanMessages);
        }
        em.remove(tblEventType);
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException) EntityManager(javax.persistence.EntityManager) TblEventType(com.intel.mtwilson.as.data.TblEventType) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 12 with EntityNotFoundException

use of javax.persistence.EntityNotFoundException in project OpenAttestation by OpenAttestation.

the class MwAssetTagCertificateJpaController method destroy.

public void destroy(Integer id) throws NonexistentEntityException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        MwAssetTagCertificate mwAssetTagCertificate;
        try {
            mwAssetTagCertificate = em.getReference(MwAssetTagCertificate.class, id);
            mwAssetTagCertificate.getId();
        } catch (EntityNotFoundException enfe) {
            throw new NonexistentEntityException("The mwAssetTagCertificate with id " + id + " no longer exists.", enfe);
        }
        em.remove(mwAssetTagCertificate);
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException) MwAssetTagCertificate(com.intel.mtwilson.as.data.MwAssetTagCertificate)

Example 13 with EntityNotFoundException

use of javax.persistence.EntityNotFoundException in project OpenAttestation by OpenAttestation.

the class MwCertificateX509JpaController method destroy.

public void destroy(Integer id) throws NonexistentEntityException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        MwCertificateX509 mwCertificateX509;
        try {
            mwCertificateX509 = em.getReference(MwCertificateX509.class, id);
            mwCertificateX509.getId();
        } catch (EntityNotFoundException enfe) {
            throw new NonexistentEntityException("The mwCertificateX509 with id " + id + " no longer exists.", enfe);
        }
        em.remove(mwCertificateX509);
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) MwCertificateX509(com.intel.mtwilson.as.data.MwCertificateX509) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 14 with EntityNotFoundException

use of javax.persistence.EntityNotFoundException in project sic by belluccifranco.

the class UsuarioServiceImpl method eliminar.

@Override
@Transactional
public void eliminar(long idUsuario) {
    Usuario usuario = this.getUsuarioPorId(idUsuario);
    if (usuario == null) {
        throw new EntityNotFoundException(ResourceBundle.getBundle("Mensajes").getString("mensaje_usuario_no_existente"));
    }
    this.validarOperacion(TipoDeOperacion.ELIMINACION, usuario);
    usuario.setEliminado(true);
    usuarioRepository.save(usuario);
}
Also used : Usuario(sic.modelo.Usuario) EntityNotFoundException(javax.persistence.EntityNotFoundException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with EntityNotFoundException

use of javax.persistence.EntityNotFoundException in project sic by belluccifranco.

the class PedidoServiceImpl method buscarConCriteria.

@Override
public List<Pedido> buscarConCriteria(BusquedaPedidoCriteria criteria) {
    //Fecha
    if (criteria.isBuscaPorFecha() == true & (criteria.getFechaDesde() == null | criteria.getFechaHasta() == null)) {
        throw new BusinessServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_pedido_fechas_busqueda_invalidas"));
    }
    if (criteria.isBuscaPorFecha() == true) {
        Calendar cal = new GregorianCalendar();
        cal.setTime(criteria.getFechaDesde());
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        criteria.setFechaDesde(cal.getTime());
        cal.setTime(criteria.getFechaHasta());
        cal.set(Calendar.HOUR_OF_DAY, 23);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);
        criteria.setFechaHasta(cal.getTime());
    }
    //Empresa
    if (criteria.getEmpresa() == null) {
        throw new EntityNotFoundException(ResourceBundle.getBundle("Mensajes").getString("mensaje_empresa_no_existente"));
    }
    //Cliente
    if (criteria.isBuscaCliente() == true && criteria.getCliente() == null) {
        throw new BusinessServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_cliente_vacio_razonSocial"));
    }
    //Usuario
    if (criteria.isBuscaUsuario() == true && criteria.getUsuario() == null) {
        throw new BusinessServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_usuario_vacio_nombre"));
    }
    QPedido qpedido = QPedido.pedido;
    BooleanBuilder builder = new BooleanBuilder();
    builder.and(qpedido.empresa.eq(criteria.getEmpresa()).and(qpedido.eliminado.eq(false)));
    if (criteria.isBuscaPorFecha() == true) {
        FormatterFechaHora formateadorFecha = new FormatterFechaHora(FormatterFechaHora.FORMATO_FECHAHORA_INTERNACIONAL);
        DateExpression<Date> fDesde = Expressions.dateTemplate(Date.class, "convert({0}, datetime)", formateadorFecha.format(criteria.getFechaDesde()));
        DateExpression<Date> fHasta = Expressions.dateTemplate(Date.class, "convert({0}, datetime)", formateadorFecha.format(criteria.getFechaHasta()));
        builder.and(qpedido.fecha.between(fDesde, fHasta));
    }
    if (criteria.isBuscaCliente() == true) {
        builder.and(qpedido.cliente.eq(criteria.getCliente()));
    }
    if (criteria.isBuscaUsuario() == true) {
        builder.and(qpedido.usuario.eq(criteria.getUsuario()));
    }
    if (criteria.isBuscaPorNroPedido() == true) {
        builder.and(qpedido.nroPedido.eq(criteria.getNroPedido()));
    }
    List<Pedido> pedidos = new ArrayList<>();
    pedidoRepository.findAll(builder, new Sort(Sort.Direction.DESC, "fecha")).iterator().forEachRemaining(pedidos::add);
    return this.calcularTotalActualDePedidos(pedidos);
}
Also used : FormatterFechaHora(sic.util.FormatterFechaHora) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) RenglonPedido(sic.modelo.RenglonPedido) QPedido(sic.modelo.QPedido) Pedido(sic.modelo.Pedido) EstadoPedido(sic.modelo.EstadoPedido) GregorianCalendar(java.util.GregorianCalendar) ArrayList(java.util.ArrayList) EntityNotFoundException(javax.persistence.EntityNotFoundException) QPedido(sic.modelo.QPedido) Date(java.util.Date) BusinessServiceException(sic.service.BusinessServiceException) BooleanBuilder(com.querydsl.core.BooleanBuilder) Sort(org.springframework.data.domain.Sort)

Aggregations

EntityNotFoundException (javax.persistence.EntityNotFoundException)75 EntityManager (javax.persistence.EntityManager)20 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)18 ServiceException (gov.ca.cwds.rest.services.ServiceException)15 Transactional (org.springframework.transaction.annotation.Transactional)14 BusinessServiceException (sic.service.BusinessServiceException)11 Test (org.junit.Test)10 Calendar (java.util.Calendar)9 GregorianCalendar (java.util.GregorianCalendar)9 ArrayList (java.util.ArrayList)7 BooleanBuilder (com.querydsl.core.BooleanBuilder)6 TblMle (com.intel.mtwilson.as.data.TblMle)5 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)4 TblModuleManifest (com.intel.mtwilson.as.data.TblModuleManifest)4 PersistenceException (javax.persistence.PersistenceException)4 Sort (org.springframework.data.domain.Sort)4 TblHosts (com.intel.mtwilson.as.data.TblHosts)3 OptimisticLockException (javax.persistence.OptimisticLockException)3 TblEventType (com.intel.mtwilson.as.data.TblEventType)2 TblHostSpecificManifest (com.intel.mtwilson.as.data.TblHostSpecificManifest)2